Created the config.cpp

This commit is contained in:
Mathias Wagner 2023-10-29 14:22:52 +01:00
parent 1c07fcd81b
commit 7ddf4297ed
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

31
src/api/config.cpp Normal file
View File

@ -0,0 +1,31 @@
#include <fstream>
#include <iostream>
#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;
}