diff --git a/services/lib/src/GlobalTools.cpp b/services/lib/src/GlobalTools.cpp index 85f8e3a0b..00880e107 100644 --- a/services/lib/src/GlobalTools.cpp +++ b/services/lib/src/GlobalTools.cpp @@ -1,35 +1,38 @@ #include "GlobalTools.h" #include #include #include #include namespace comm { namespace network { uint64_t getCurrentTimestamp() { using namespace std::chrono; return duration_cast(system_clock::now().time_since_epoch()) .count(); } +bool hasEnvFlag(const std::string &flag) { + if (std::getenv(flag.c_str()) == nullptr) { + return false; + } + return std::string(std::getenv(flag.c_str())) == "1"; +} + std::string decorateTableName(const std::string &baseName) { std::string suffix = ""; - if (std::getenv("COMM_TEST_SERVICES") != nullptr && - std::string(std::getenv("COMM_TEST_SERVICES")) == "1") { + if (hasEnvFlag("COMM_TEST_SERVICES")) { suffix = "-test"; } return baseName + suffix; } bool isDevMode() { - if (std::getenv("COMM_SERVICES_DEV_MODE") == nullptr) { - return false; - } - return std::string(std::getenv("COMM_SERVICES_DEV_MODE")) == "1"; + return hasEnvFlag("COMM_SERVICES_DEV_MODE"); } } // namespace network } // namespace comm diff --git a/services/lib/src/GlobalTools.h b/services/lib/src/GlobalTools.h index 8f8c6836c..eba7e64b4 100644 --- a/services/lib/src/GlobalTools.h +++ b/services/lib/src/GlobalTools.h @@ -1,16 +1,18 @@ #pragma once #include #include namespace comm { namespace network { uint64_t getCurrentTimestamp(); +bool hasEnvFlag(const std::string &flag); + std::string decorateTableName(const std::string &baseName); bool isDevMode(); } // namespace network } // namespace comm