use serde_derive::Deserialize; use crate::constants; use crate::errors::EmgauwaError; #[derive(Clone, Debug, Deserialize)] #[serde(default)] #[allow(unused)] pub struct Server { pub host: String, pub port: u16, } #[derive(Clone, Debug, Deserialize)] #[serde(default)] #[allow(unused)] pub struct Logging { pub level: String, pub file: String, } #[derive(Clone, Debug, Deserialize, Default)] #[serde(default)] #[allow(unused)] pub struct Permissions { pub user: String, pub group: String, } impl Default for Server { fn default() -> Self { Server { host: String::from("127.0.0.1"), port: constants::DEFAULT_PORT, } } } impl Default for Logging { fn default() -> Self { Logging { level: String::from("info"), file: String::from("stdout"), } } } pub fn load(config_name: &str, env_prefix: &str) -> Result where for<'de> T: serde::Deserialize<'de>, { let local_file = config::File::with_name(&format!("./emgauwa-{}", config_name)).required(false); config::Config::builder() .add_source(local_file) .add_source( config::Environment::with_prefix(&format!("EMGAUWA_{}", env_prefix)) .prefix_separator("__") .separator("__"), ) .build()? .try_deserialize::() .map_err(EmgauwaError::from) }