mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
38 lines
1.1 KiB
C++
38 lines
1.1 KiB
C++
|
|
#include "Config.h"
|
|||
|
|
|
|||
|
|
#include <fstream>
|
|||
|
|
|
|||
|
|
#include "common/JsonN.h"
|
|||
|
|
#include "Logger.h"
|
|||
|
|
|
|||
|
|
AppOption Config::option;
|
|||
|
|
|
|||
|
|
bool Config::init(std::string filename)
|
|||
|
|
{
|
|||
|
|
NJson jsonroot;
|
|||
|
|
bool ret = NJsonLoad(filename, jsonroot);
|
|||
|
|
if (!ret)
|
|||
|
|
{
|
|||
|
|
XLOGE() << "[APP] load config failed, filename=" << filename;
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
XLOGI() << "[APP] load config success, filename=" << filename;
|
|||
|
|
|
|||
|
|
if (jsonroot.contains("database"))
|
|||
|
|
{
|
|||
|
|
NJson json = jsonroot.at("database");
|
|||
|
|
option.database.host = json.contains("host") ? json.at("host") : "";
|
|||
|
|
option.database.port = json.contains("port") ? json.at("port") : 0;
|
|||
|
|
option.database.user = json.contains("user") ? json.at("user") : "";
|
|||
|
|
option.database.passwd = json.contains("passwd") ? json.at("passwd") : "";
|
|||
|
|
option.database.dbname = json.contains("dbname") ? json.at("dbname") : "";
|
|||
|
|
|
|||
|
|
XLOGI() << "[APP] load database config end. host=" << option.database.host;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
XLOGI() << "[APP] load database config error: not found. host=" << option.database.host;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|