47 lines
1.2 KiB
C++
47 lines
1.2 KiB
C++
#include "config.hpp"
|
|
#include <fstream>
|
|
#include <sstream>
|
|
#include <iostream>
|
|
#include <json.hpp>
|
|
|
|
namespace simple_object_storage {
|
|
|
|
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 simple_object_storage
|