pixwhile/config.cpp

21 lines
601 B
C++
Raw Normal View History

2023-04-03 08:57:51 +00:00
#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());
2023-04-03 08:57:51 +00:00
}
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));
}
2023-04-06 12:24:09 +00:00
config.image_proxy_url = j.at("image_proxy_url").get<std::string>();
2023-04-03 08:57:51 +00:00
}