b453d5d
use std::net::IpAddr;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(default)]
pub struct GithostConfig {
pub enabled: Option<bool>,
pub http_bind_addr: Option<IpAddr>,
pub http_port: Option<u16>,
}
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(())
}
}