add IsValidNormalConfig

This commit is contained in:
aozhiwei 2019-09-03 13:31:49 +08:00
parent a6cc881c1c
commit f7c0890bc8
2 changed files with 21 additions and 0 deletions

View File

@ -337,4 +337,23 @@ namespace f8
return !getenv("SERVER_ENV"); return !getenv("SERVER_ENV");
} }
bool IsValidNormalConfig(a8::XObject& conf, std::vector<std::string> fields)
{
if (conf.GetType() != a8::XOT_ARRAY) {
abort();
}
for (int i = 0; i < conf.Size(); ++i) {
std::shared_ptr<a8::XObject> node = conf.At(i);
if (node->At("instance_id")->AsXValue().GetInt() != i + 1) {
abort();
}
for (std::string& field_name : fields) {
if (!node->HasKey(field_name)) {
abort();
}
}
}
return true;
}
} }

View File

@ -113,4 +113,6 @@ namespace f8
int ExtractChannelIdFromAccountId(const std::string& accountid); int ExtractChannelIdFromAccountId(const std::string& accountid);
bool IsOnlineEnv(); bool IsOnlineEnv();
bool IsValidNormalConfig(a8::XObject& conf, std::vector<std::string> fields);
} }