diff options
Diffstat (limited to 'web/src/config.cpp')
| -rw-r--r-- | web/src/config.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/web/src/config.cpp b/web/src/config.cpp new file mode 100644 index 0000000..dbeb01e --- /dev/null +++ b/web/src/config.cpp @@ -0,0 +1,46 @@ +#include "config.hpp" + +#include <fstream> +#include <sstream> + +#include "crow/logging.h" + +namespace botweb { + std::optional<Configuration> parse_configuration_from_file( + const std::string &file_path) { + std::ifstream ifs(file_path); + + if (!ifs.is_open()) { + CROW_LOG_ERROR << "Failed to open the configuration file at " + << file_path; + return std::nullopt; + } + + Configuration cfg; + + std::string line; + while (std::getline(ifs, line, '\n')) { + std::istringstream iss(line); + std::string key; + std::string value; + + std::getline(iss, key, '='); + std::getline(iss, value); + + for (char &c : key) { + c = tolower(c); + } + + if (key == "contact_name") { + cfg.contact_name = value; + } else if (key == "contact_url") { + cfg.contact_url = value; + } + } + + CROW_LOG_INFO << "Successfully loaded the configuration from " << file_path + << "'"; + + return cfg; + } +} |
