extern crate serde_derive; extern crate toml; use std::collections::HashMap; use std::path::Path; use toml::de::Error; #[derive(Debug, Deserialize, Clone)] pub struct Config { pub port: u16, pub host: String, pub server: Vec, } #[derive(Debug, Deserialize, Clone)] pub struct Server { pub hostname: String, pub dir: String, pub key: String, pub cert: String, pub index: Option, pub cgi: Option, pub cgipath: Option, pub cgienv: Option>, pub usrdir: Option, pub proxy: Option>, pub redirect: Option>, } #[derive(Debug, Clone)] pub struct ServerCfg { pub port: u16, pub server: Server, } impl Config { pub fn new(file: &Path) -> Result { let fd = std::fs::read_to_string(file).unwrap(); let config: Config = toml::from_str(&fd).unwrap(); return Ok(config); } pub fn to_map(&self) -> HashMap { let mut map = HashMap::new(); for srv in &self.server { map.insert( srv.hostname.clone(), ServerCfg { port: self.port.clone(), server: srv.clone(), }, ); } map } }