Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
Loading...
Searching...
No Matches
ConfigFile.hpp
Go to the documentation of this file.
1#pragma once
4#include <orbit/http/json.hpp>
5#include <stdexcept>
6#include <string>
7
8namespace orbit::config {
9
11class ConfigError : public std::runtime_error {
12public:
13 using std::runtime_error::runtime_error;
14};
15
48class Config {
49public:
51
57 static Config load(const std::string& path, int argc = 0, char* argv[] = nullptr,
59
61 static Config from_json(nlohmann::json document, int argc = 0, char* argv[] = nullptr,
63
66 const nlohmann::json& section(const std::string& name) const;
67
69 const nlohmann::json& document() const { return document_; }
70
72 static ServerConfig server_from_json(const nlohmann::json& server_section);
73
74private:
75 nlohmann::json document_ = nlohmann::json::object();
76};
77
78} // namespace orbit::config
a class to store JSON values
Definition json.hpp:19401
A configuration problem, naming the key path ("server.port: ...").
Definition ConfigFile.hpp:11
An application's configuration: a JSON file, then ORBIT_* environment variables, then command-line fl...
Definition ConfigFile.hpp:48
nlohmann::json document_
Definition ConfigFile.hpp:75
const nlohmann::json & document() const
The whole document after environment overrides.
Definition ConfigFile.hpp:69
const nlohmann::json & section(const std::string &name) const
static Config from_json(nlohmann::json document, int argc=0, char *argv[]=nullptr, ServerConfig::ParseMode mode=ServerConfig::ParseMode::Lenient)
As load(), from a document already in memory (tests, generated config).
ServerConfig server
Definition ConfigFile.hpp:50
static ServerConfig server_from_json(const nlohmann::json &server_section)
The server section as a ServerConfig (strictly validated).
static Config load(const std::string &path, int argc=0, char *argv[]=nullptr, ServerConfig::ParseMode mode=ServerConfig::ParseMode::Lenient)
Reads path, applies the environment, then the command line (as ServerConfig::parse(); pass argc = 0 f...
Definition Config.hpp:8
Definition Config.hpp:30
ParseMode
How parse() treats a flag it does not know.
Definition Config.hpp:90
@ Lenient
Report it on stderr and carry on: the application may handle its own flags.