diff options
-rw-r--r-- | src/config.rs | 7 | ||||
-rw-r--r-- | src/main.rs | 7 |
2 files changed, 8 insertions, 6 deletions
diff --git a/src/config.rs b/src/config.rs index 6fc01d8..210a1e6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,7 +1,6 @@ -use std::{collections::HashMap, fs::read_to_string, net::SocketAddr, path::PathBuf}; - 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 { @@ -28,8 +27,8 @@ pub struct HostConfig { } impl Config { - pub fn load() -> anyhow::Result<Config> { - let raw = read_to_string("config.toml").context("reading config file")?; + pub fn load(path: &str) -> anyhow::Result<Config> { + let raw = read_to_string(path).context("reading config file")?; let config: Config = toml::from_str(&raw).context("parsing config")?; Ok(config) } diff --git a/src/main.rs b/src/main.rs index 976cad5..f507ed5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ pub mod config; use crate::config::Config; -use anyhow::{bail, Context, Result}; +use anyhow::{anyhow, bail, Context, Result}; use http_body_util::{combinators::BoxBody, BodyExt}; use hyper::{ body::Incoming, @@ -24,7 +24,10 @@ use tokio_rustls::TlsAcceptor; async fn main() -> anyhow::Result<()> { env_logger::init_from_env("LOG"); - let config = Arc::new(Config::load()?); + let config_path = std::env::args().skip(1).next().ok_or(anyhow!( + "first argument is expected to be the configuration file" + ))?; + let config = Arc::new(Config::load(&config_path)?); tokio::select! { x = serve_http(config.clone()) => x.context("serving http")?, |