17
crates/server/src/config_loader.rs
Normal file
17
crates/server/src/config_loader.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use config::AppConfig;
|
||||
|
||||
const CONFIG_FILE: &str = "config.toml";
|
||||
|
||||
pub fn load() -> Result<AppConfig, Box<dyn std::error::Error>> {
|
||||
let path = std::path::Path::new(CONFIG_FILE);
|
||||
|
||||
if path.exists() {
|
||||
let content = std::fs::read_to_string(path)?;
|
||||
let config: AppConfig = toml::from_str(&content)?;
|
||||
tracing::info!(path = CONFIG_FILE, "loaded config from file");
|
||||
Ok(config)
|
||||
} else {
|
||||
tracing::info!("no config file found, using defaults");
|
||||
Ok(AppConfig::default())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user