Config singleton

FossilOrigin-Name: 49a2dd0e8e60f2fda887dd815ef38ad140c22ccffbd85338553aa17b033c882c
This commit is contained in:
nekobit 2022-10-02 05:10:13 +00:00
parent fabd54e26d
commit 455261a8dc
3 changed files with 56 additions and 3 deletions

21
src/config/config_http.h Normal file
View file

@ -0,0 +1,21 @@
/*
* Wormhole - Federated social network
* Copyright (C) 2022 Nekobit
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once

View file

@ -17,8 +17,28 @@
*/
#include "config_loader.h"
#include "config_http.h"
using namespace Config;
namespace
{
// Global instance
ConfigLoader inst{};
}
ConfigLoader& instance()
{
return inst;
}
ConfigLoader::ConfigLoader()
{}
void ConfigLoader::load_config(const std::filesystem::path& path)
{
// Make sure it's loaded
YAML::Node node = YAML::LoadFile(path);
}

View file

@ -18,7 +18,9 @@
#pragma once
#include <filesystem>
#include <yaml-cpp/yaml.h>
#include <optional>
namespace Config
{
@ -27,8 +29,18 @@ namespace Config
public:
ConfigLoader();
~ConfigLoader() = default;
private:
/** @brief Config parser for YAML */
YAML::Node cfg;
void load_config(const std::filesystem::path& path);
/**
* @brief List of commonly used configuration options
*/
struct CommonConfig
{
Config::HTTP http;
} config;
};
// Global instance of config
ConfigLoader& instance();
}