提交 e4928744 authored 作者: bruce.lu's avatar bruce.lu

init

上级 6c00a563
......@@ -31,6 +31,11 @@ class HttpSrv{
ret["code"] = 0;
ret["msg"] = "ok";
ret["time"] = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
spdlog::info(body);
if(body.empty()){
ret["code"] = 1;
ret["msg"] = "no body payload";
}else{
try{
json newConfig = json::parse(body);
if(newConfig.count("data") == 0 || newConfig["data"].size() == 0) {
......@@ -86,13 +91,15 @@ class HttpSrv{
// save configmap
LVDB::setValue(this->configMap, "configmap");
ret["data"] = newConfig["data"];
}
}catch(exception &e) {
ret.clear();
ret["code"] = -1;
ret["msg"] = e.what();
}
}
return ret;
}
......@@ -110,11 +117,10 @@ class HttpSrv{
svr.Post("/register", [this](const Request& req, Response& res){
json ret;
try{
json config = json::parse(req.body);
string sn = req.get_param_value("sn");
string module = req.get_param_value("module");
if(sn.empty()||module.empty()){
throw "no para sn/module";
throw StrException("no para sn/module");
}
string modname = module.substr(0,4);
if(modname == "evml") {
......@@ -130,7 +136,7 @@ class HttpSrv{
spdlog::info("evcloudsvc no such edge module registred: {}, create new entry", key);
ret = this->config(req.body);
if(ret["code"] == 0) {
ret["data"] = config["data"];
//ret["data"] =ret["data"];
}
}else{
// TODO: calc md5
......
......@@ -108,4 +108,12 @@ vector<string> split(const std::string& s, char delimiter)
} // namespace cloudutils
struct StrException : public std::exception
{
std::string s;
StrException(std::string ss) : s(ss) {}
~StrException() throw () {} // Updated
const char* what() const throw() { return s.c_str(); }
};
#endif
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论