From 1284ac8ac8ab0797b908fd9cc8db8b682bc4373f Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 11 Feb 2023 21:45:16 +0100 Subject: works --- src/config.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/config.rs (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..527e159 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,34 @@ +use std::{collections::HashMap, fs::read_to_string, net::SocketAddr, path::PathBuf}; + +use anyhow::Context; +use serde::{Deserialize, Serialize}; + +#[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 {} + +impl Config { + pub fn load() -> anyhow::Result { + let raw = read_to_string("config.toml").context("reading config file")?; + let config: Config = toml::from_str(&raw).context("parsing config")?; + Ok(config) + } +} -- cgit v1.2.3-70-g09d2