1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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(())
}
|