use std::net::IpAddr; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Default, Serialize, Deserialize)] #[serde(default)] pub struct GithostConfig { pub enabled: Option, pub http_bind_addr: Option, pub http_port: Option, } impl GithostConfig { pub fn enabled(&self) -> bool { self.enabled.unwrap_or(true) } pub fn http_bind_addr(&self) -> IpAddr { self.http_bind_addr .unwrap_or_else(|| "0.0.0.0".parse().expect("static ip")) } pub fn http_port(&self) -> u16 { self.http_port.unwrap_or(9418) } pub fn is_valid(&self) -> Result<(), String> { if !self.enabled() { return Ok(()); } if self.http_port() == 0 { return Err("githost.http_port must be greater than 0".to_string()); } Ok(()) } }