use config::File; use serde::Deserialize; use crate::auth; #[derive(Debug, Clone, Deserialize)] #[serde(default)] pub struct Config { pub serveraddr: String, pub pingtimeout: i64, pub pingthreshold: u64, pub auth: Auth, } impl Default for Config { fn default() -> Self { Self { serveraddr: "0.0.0.0:7229".to_string(), pingtimeout: 10, pingthreshold: 1, auth: Default::default(), } } } #[derive(Debug, Clone, Deserialize)] pub struct Auth { pub method: auth::Methods, pub secret: String, } impl Default for Auth { fn default() -> Self { Self { method: auth::Methods::None, secret: String::new(), } } } impl Config { pub fn load() -> Result { let config = config::Config::builder() .add_source(File::with_name("/etc/webol").required(false)) .add_source(File::with_name("config.toml").required(false)) .add_source(config::Environment::with_prefix("WEBOL").separator("_")) .build()?; config.try_deserialize() } }