use std::{fs::File, io::Write, path::PathBuf}; use statsrv::Service; #[derive(Debug, Clone, serde::Deserialize)] pub struct Config { pub title: String, pub template_path: PathBuf, pub output_dir: Option, pub address: Option, pub services: Vec, } fn main() -> Result<(), main_error::MainError> { let mut args = std::env::args().skip(1); let config_path = args .next() .unwrap_or_else(|| "/etc/statsrv.toml".to_string()); let config_file = File::open(config_path)?; let config_toml = std::io::read_to_string(config_file)?; let Config { title, template_path: template, output_dir, address: _, services, } = toml::from_str(&config_toml)?; let template_file = File::open(template)?; let template = std::io::read_to_string(template_file)?; let status_page = statsrv::generate(title, services, template); if let Some(output_dir) = output_dir { std::fs::create_dir_all(&output_dir)?; let mut html_writer = File::create(output_dir.join("index.html"))?; html_writer.write_all(status_page.as_bytes())?; } Ok(()) }