#include "config.hpp" #include #include namespace svapi { Config Config::fromJson(const nlohmann::json& j) { Config c; c.logLevel = j.value("log_level", c.logLevel); if (j.contains("http") && j["http"].is_object()) { const auto& h = j["http"]; c.httpBind = h.value("bind_address", c.httpBind); c.httpPort = h.value("port", c.httpPort); } if (j.contains("database") && j["database"].is_object()) { c.dbAddress = j["database"].value("address", c.dbAddress); } return c; } Config Config::load(const std::string& path) { std::ifstream f(path); if (!f) throw std::runtime_error("cannot open config file: " + path); nlohmann::json j; f >> j; return fromJson(j); } } // namespace svapi