diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..2ff9fd3 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,42 @@ +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<PathBuf>, + pub address: Option<String>, + pub services: Vec<Service>, +} + +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(()) +} |