Add configuration from toml file
This commit is contained in:
49
src/config.hpp
Normal file
49
src/config.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace weaseldb {
|
||||
|
||||
struct ServerConfig {
|
||||
std::string bind_address = "127.0.0.1";
|
||||
int port = 8080;
|
||||
size_t max_request_size_bytes =
|
||||
1024 * 1024; // 1MB default for 413 Content Too Large
|
||||
};
|
||||
|
||||
struct CommitConfig {
|
||||
size_t min_request_id_length = 20; // Minimum length for request_id entropy
|
||||
std::chrono::hours request_id_retention_time{
|
||||
24}; // How long to keep request IDs
|
||||
size_t request_id_retention_versions =
|
||||
100000000; // Min versions to retain request IDs
|
||||
};
|
||||
|
||||
struct SubscriptionConfig {
|
||||
size_t max_buffer_size_bytes =
|
||||
10 * 1024 * 1024; // 10MB buffer for unconsumed data
|
||||
std::chrono::seconds keepalive_interval{30}; // Keepalive comment frequency
|
||||
};
|
||||
|
||||
struct Config {
|
||||
ServerConfig server;
|
||||
CommitConfig commit;
|
||||
SubscriptionConfig subscription;
|
||||
};
|
||||
|
||||
class ConfigParser {
|
||||
public:
|
||||
static std::optional<Config> load_from_file(const std::string &file_path);
|
||||
static std::optional<Config>
|
||||
parse_toml_string(const std::string &toml_content);
|
||||
|
||||
private:
|
||||
static void parse_server_config(const auto &toml_data, ServerConfig &config);
|
||||
static void parse_commit_config(const auto &toml_data, CommitConfig &config);
|
||||
static void parse_subscription_config(const auto &toml_data,
|
||||
SubscriptionConfig &config);
|
||||
};
|
||||
|
||||
} // namespace weaseldb
|
||||
Reference in New Issue
Block a user