diff options
author | metamuffin <metamuffin@disroot.org> | 2023-02-11 21:45:16 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-02-11 21:45:16 +0100 |
commit | 1284ac8ac8ab0797b908fd9cc8db8b682bc4373f (patch) | |
tree | 060ebed333d4127663e9f1c21db514a3486a6b58 /src/config.rs | |
download | gnix-1284ac8ac8ab0797b908fd9cc8db8b682bc4373f.tar gnix-1284ac8ac8ab0797b908fd9cc8db8b682bc4373f.tar.bz2 gnix-1284ac8ac8ab0797b908fd9cc8db8b682bc4373f.tar.zst |
works
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 34 |
1 files changed, 34 insertions, 0 deletions
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<HttpConfig>, + pub https: Option<HttpsConfig>, + pub hosts: HashMap<String, HostConfig>, +} + +#[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<Config> { + let raw = read_to_string("config.toml").context("reading config file")?; + let config: Config = toml::from_str(&raw).context("parsing config")?; + Ok(config) + } +} |