pixwhile/config.cpp

21 lines
622 B
C++

#include <stdexcept>
#include "file.h"
#include "config.h"
Config load_config(const char* path) {
File config_file(path, "r");
return nlohmann::json::parse(config_file.get(), nullptr, true, true);
}
void from_json(const nlohmann::json& j, Config& config) {
using namespace std::string_literals;
j.at("bind_host").get_to(config.bind_host);
j.at("bind_port").get_to(config.bind_port);
if (config.bind_port < 0) {
throw std::invalid_argument("Invalid port to bind to: "s + std::to_string(config.bind_port));
}
config.image_proxy_url = j.at("image_proxy_url").get<std::string>();
}