This commit is contained in:
Your Name
2025-04-30 21:30:55 +12:00
parent 69ecc77d51
commit fe9c940a22
14 changed files with 26367 additions and 2 deletions

47
src/config.cpp Normal file
View 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