From 7ddf4297ed03de63e9756d55cb24685fcaf631d5 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sun, 29 Oct 2023 14:22:52 +0100 Subject: [PATCH] Created the config.cpp --- src/api/config.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/api/config.cpp diff --git a/src/api/config.cpp b/src/api/config.cpp new file mode 100644 index 0000000..309ae57 --- /dev/null +++ b/src/api/config.cpp @@ -0,0 +1,31 @@ +#include +#include +#include "config.h" + +#define CONFIG_FILE "config.json" + +bool config::is_valid_config(const json& config) { + + if (!config.contains("token")) { + std::cout << "Config file is missing \"token\" field." << std::endl; + return false; + } + + return true; +} + +json config::read_config() { + json config; + std::ifstream config_file(CONFIG_FILE); + + if (!config_file.is_open()) { + std::cout << "Failed to open config file. Please create a " << CONFIG_FILE << " file in the same directory as the executable." << std::endl; + exit(1); + } + + config_file >> config; + + if (!is_valid_config(config)) exit(1); + + return config; +} \ No newline at end of file