Created the config.cpp
This commit is contained in:
parent
1c07fcd81b
commit
7ddf4297ed
31
src/api/config.cpp
Normal file
31
src/api/config.cpp
Normal 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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user