aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
blob: 6fc01d8d5abf6c5dd5c1f31d0b14941ae358418d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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 {
    pub backend: SocketAddr,
}

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)
    }
}