use anyhow::Context; use serde::{Deserialize, Serialize}; use std::{collections::HashMap, fs::read_to_string, net::SocketAddr, path::PathBuf}; #[derive(Debug, Serialize, Deserialize)] pub struct Config { pub http: Option, pub https: Option, pub hosts: HashMap, } #[derive(Debug, Serialize, Deserialize)] pub struct HttpConfig { pub bind: SocketAddr, } #[derive(Debug, Serialize, Deserialize)] pub struct HttpsConfig { pub bind: SocketAddr, pub tls_cert: PathBuf, pub tls_key: PathBuf, } #[derive(Debug, Serialize, Deserialize)] pub struct HostConfig { pub backend: SocketAddr, } impl Config { pub fn load(path: &str) -> anyhow::Result { let raw = read_to_string(path).context("reading config file")?; let config: Config = toml::from_str(&raw).context("parsing config")?; Ok(config) } }