summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs34
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)
+ }
+}