diff options
author | neodarz <neodarz@neodarz.net> | 2019-09-10 16:20:11 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2019-09-10 16:20:11 +0200 |
commit | 1ae302dae3df2cb48c99ebdf407e490dca97d5fd (patch) | |
tree | 491e1f6ee0708ea379e3ead5f48246a36b88c0e9 /main.cpp | |
parent | cc42e3be1c2cfe357efaaa49b6d3738f037a9696 (diff) | |
parent | cc8c1ad450667c8f6f983ba4f0d640accdcb49cf (diff) | |
download | umosapicpp-1ae302dae3df2cb48c99ebdf407e490dca97d5fd.tar.xz umosapicpp-1ae302dae3df2cb48c99ebdf407e490dca97d5fd.zip |
Merge branch 'restbed_rewrite'
Diffstat (limited to '')
-rw-r--r-- | main.cpp | 39 |
1 files changed, 19 insertions, 20 deletions
@@ -8,14 +8,12 @@ #include "config.h" #include "api/umosapi.h" -std::map<std::string, std::string> config; -using namespace std; -using namespace Pistache; +std::map<std::string, std::string> config; int main(int argc, char *argv[]) { - string config_path = ""; + std::string config_path = ""; const char *homedir; if ((homedir = getenv("XDG_CONFIG_HOME")) == NULL || (homedir = getenv("HOME")) == NULL) { @@ -26,16 +24,16 @@ int main(int argc, char *argv[]) { config_path.append("/.config/umosapi/config.txt"); bool showHelp = false; - int config_port = 9080; + config["port"] = "9080"; int thr = 2; auto cli = clara::detail::Help(showHelp) | clara::detail::Opt( config_path, "config" )["-c"]["--config"]("Config file path. Default `~/.config/umosapi/config.txt`.") - | clara::detail::Opt( config_port, "port" )["-p"]["--port"]("Port to listen. Default: `9080`.") + | clara::detail::Opt( config["port"], "port" )["-p"]["--port"]("Port to listen. Default: `9080`.") | clara::detail::Opt( thr, "treads" )["-t"]["--threads"]("Number of threads. Default: `2`."); auto result = cli.parse( clara::detail::Args( argc, argv ) ); if( !result ) { - std::cerr << "Error in command line: " << result.errorMessage() << std::endl; + std::cerr << "ERROR: Error in command line: " << result.errorMessage() << std::endl; std::cerr << cli << std::endl; exit(1); } @@ -45,27 +43,28 @@ int main(int argc, char *argv[]) { exit(1); } - Address addr(Ipv4::any(), Port(config_port)); + std::cout << "INFO: Using " << std::thread::hardware_concurrency() << " cores"; + std::cout << " - " << thr << " threads" << std::endl; + std::cout << "INFO: Listen on 0.0.0.0:" << config["port"] << std::endl; - cout << "Using " << hardware_concurrency() << " cores"; - cout << " - " << thr << " threads" << endl; - cout << "Listen on 0.0.0.0:" << config_port << endl; - - cout << "Using config file '" << config_path << "'" << endl; + std::cout << "INFO: Using config file '" << config_path << "'" << std::endl; if (!std::filesystem::exists(config_path)) { - cout << "Error fatal : config file '" << config_path << "' not found" << endl; - cout << "config.txt is search here: ~/.config/umosapi/config.txt" << endl; + std::cout << "ERROR: Error fatal : config file '" << config_path << "' not found" << std::endl; + std::cout << "ERROR: config.txt is search here: ~/.config/umosapi/config.txt" << std::endl; exit (EXIT_FAILURE); } load_config(config_path); - cout << "Using swaggerui " << config["swaggerui"] << " path" << endl; - cout << "Using mongoURI " << config["mongoURI"] << endl; + std::cout << "Using swaggerui " << config["swaggerui"] << " path" << std::endl; + std::cout << "INFO: No support for swagger for the moment" << std::endl; + std::cout << "INFO: Using mongoURI " << config["mongoURI"] << std::endl; + + UmosapiService::Api umosapi; + umosapi.init(); + umosapi.start(std::stoi(config["port"]), thr); - UmosapiService umosapi(addr); + return EXIT_SUCCESS; - umosapi.init(thr); - umosapi.start(config["swaggerui"]); } |