blob: dbeb01eee2b59db50196ab3283802c6c6bdb1917 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;
}
}
|