20 lines
528 B
C++
20 lines
528 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());
|
||
|
}
|
||
|
|
||
|
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));
|
||
|
}
|
||
|
}
|