aboutsummaryrefslogtreecommitdiff
path: root/config.cpp
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-08-07 10:40:36 +0200
committerneodarz <neodarz@neodarz.net>2019-08-07 10:40:36 +0200
commit7dc4e5bfc85474700b3731fc06e48a0e5c1d387b (patch)
treee8f940b7334062d78f992d4a0cb3eab684f10502 /config.cpp
parent2cb04d30c6552ac394278ca3dda5b7246d0f16b8 (diff)
downloadumosapicpp-7dc4e5bfc85474700b3731fc06e48a0e5c1d387b.tar.xz
umosapicpp-7dc4e5bfc85474700b3731fc06e48a0e5c1d387b.zip
Refactoring loader configuration
Diffstat (limited to 'config.cpp')
-rw-r--r--config.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/config.cpp b/config.cpp
new file mode 100644
index 0000000..477e9fb
--- /dev/null
+++ b/config.cpp
@@ -0,0 +1,51 @@
+#include "config.h"
+#include "shared.h"
+
+void load_config(std::string config_path) {
+std::ifstream is_file(config_path);
+ std::string line;
+ while( std::getline(is_file, line) )
+ {
+ std::istringstream is_line(line);
+ std::string key;
+ if( std::getline(is_line, key, '=') )
+ {
+ std::string value;
+ if( std::getline(is_line, value) )
+ config[key] = value;
+ }
+ }
+ is_file.close();
+
+ std::string mongoURI = "mongodb://";
+
+
+ if (config["mongo_db"] == "") {
+ config["mongo_db"] = "umosapi";
+ }
+
+ if (config["mongo_user"] != "") {
+ mongoURI.append(config["mongo_user"] + ":");
+ }
+
+ if (config["mongo_password"] != "") {
+ mongoURI.append(config["mongo_password"] + "@");
+ }
+
+ if (config["mongo_host"] == "") {
+ config["mongo_host"] = "127.0.0.1";
+ }
+ mongoURI.append(config["mongo_host"]);
+
+ if (config["mongo_port"] == "") {
+ config["mongo_port"] = "umosapi";
+ }
+ mongoURI.append(":" + config["mongo_port"]);
+
+ if (config["swaggerui"] == "") {
+ config["swaggerui"] = "/srv/http/swagger-ui";
+ }
+
+ config["mongoURI"] = mongoURI;
+
+}