mirror of
https://forge.fsky.io/oneflux/omegafox.git
synced 2026-02-10 16:32:05 -08:00
Updated GetJson
This commit is contained in:
parent
ef6a54509f
commit
f0b18df324
1 changed files with 9 additions and 19 deletions
|
|
@ -49,9 +49,8 @@ inline const nlohmann::json& GetJson() {
|
||||||
|
|
||||||
std::call_once(initFlag, []() {
|
std::call_once(initFlag, []() {
|
||||||
std::string jsonString;
|
std::string jsonString;
|
||||||
|
|
||||||
// First try the chunked environment variables
|
|
||||||
int index = 1;
|
int index = 1;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
std::string envName = "CAMOU_CONFIG_" + std::to_string(index);
|
std::string envName = "CAMOU_CONFIG_" + std::to_string(index);
|
||||||
auto partialConfig = get_env_utf8(envName);
|
auto partialConfig = get_env_utf8(envName);
|
||||||
|
|
@ -61,36 +60,27 @@ inline const nlohmann::json& GetJson() {
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no chunked variables found, try the original CAMOU_CONFIG
|
|
||||||
if (jsonString.empty()) {
|
if (jsonString.empty()) {
|
||||||
|
// Check for the original CAMOU_CONFIG as fallback
|
||||||
auto originalConfig = get_env_utf8("CAMOU_CONFIG");
|
auto originalConfig = get_env_utf8("CAMOU_CONFIG");
|
||||||
if (originalConfig) {
|
if (originalConfig) jsonString = *originalConfig;
|
||||||
jsonString = *originalConfig;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If still empty, return an empty JSON object
|
|
||||||
if (jsonString.empty()) {
|
if (jsonString.empty()) {
|
||||||
jsonConfig = nlohmann::json{};
|
jsonConfig = nlohmann::json{};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate and parse the JSON
|
// Validate
|
||||||
try {
|
if (!nlohmann::json::accept(jsonString)) {
|
||||||
if (!nlohmann::json::accept(jsonString)) {
|
printf_stderr("ERROR: Invalid JSON passed to CAMOU_CONFIG!\n");
|
||||||
printf_stderr("ERROR: Invalid JSON passed to CAMOU_CONFIG!\n");
|
|
||||||
jsonConfig = nlohmann::json{};
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonConfig = nlohmann::json::parse(jsonString);
|
|
||||||
} catch (const nlohmann::json::exception& e) {
|
|
||||||
printf_stderr("ERROR: JSON parsing failed: %s\n", e.what());
|
|
||||||
jsonConfig = nlohmann::json{};
|
jsonConfig = nlohmann::json{};
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jsonConfig = nlohmann::json::parse(jsonString);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Return the cached JSON object
|
|
||||||
return jsonConfig;
|
return jsonConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue