.
This commit is contained in:
47
src/config.cpp
Normal file
47
src/config.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "config.hpp"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <json.hpp>
|
||||
|
||||
namespace dropshell {
|
||||
|
||||
bool load_config(const std::string& config_path, ServerConfig& config) {
|
||||
try {
|
||||
std::ifstream file(config_path);
|
||||
if (!file.is_open()) {
|
||||
std::cerr << "Failed to open config file: " << config_path << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
nlohmann::json j;
|
||||
file >> j;
|
||||
|
||||
// Parse write tokens
|
||||
if (j.contains("write_tokens")) {
|
||||
config.write_tokens = j["write_tokens"].get<std::vector<std::string>>();
|
||||
}
|
||||
|
||||
// Parse object store path
|
||||
if (j.contains("object_store_path")) {
|
||||
config.object_store_path = j["object_store_path"].get<std::string>();
|
||||
}
|
||||
|
||||
// Parse host (optional)
|
||||
if (j.contains("host")) {
|
||||
config.host = j["host"].get<std::string>();
|
||||
}
|
||||
|
||||
// Parse port (optional)
|
||||
if (j.contains("port")) {
|
||||
config.port = j["port"].get<uint16_t>();
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Error parsing config file: " << e.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace dropshell
|
Reference in New Issue
Block a user