diff --git a/src/config.rs b/src/config.rs index f616c61..7763536 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,23 +8,50 @@ const CONFIG_FILE: &str = "config.json"; #[derive(Deserialize, Serialize)] pub struct Config { + #[serde(default = "Config::default_admin_passwords")] pub admin_passwords: Vec, + #[serde(default = "Config::default_cookies_https_only")] pub cookies_https_only: bool, + #[serde(default = "Config::default_cookies_domain")] pub cookies_domain: Option, + #[serde(default = "Config::default_listen")] pub listen: SocketAddr, + #[serde(default = "Config::default_root_url")] pub root_url: String, + #[serde(default = "Config::default_title")] pub title: String, } +impl Config { + fn default_admin_passwords() -> Vec { + vec![] + } + fn default_cookies_https_only() -> bool { + false + } + fn default_cookies_domain() -> Option { + None + } + fn default_listen() -> SocketAddr { + SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 10353) + } + fn default_root_url() -> String { + "/".into() + } + fn default_title() -> String { + "ĞMarché".into() + } +} + impl Default for Config { fn default() -> Self { Self { - admin_passwords: vec![], - cookies_https_only: false, - cookies_domain: None, - listen: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 10353), - root_url: String::from("/"), - title: String::from("ĞMarché"), + admin_passwords: Self::default_admin_passwords(), + cookies_https_only: Self::default_cookies_https_only(), + cookies_domain: Self::default_cookies_domain(), + listen: Self::default_listen(), + root_url: Self::default_root_url(), + title: Self::default_title(), } } }