🗝
summary refs log tree commit diff
path: root/src/server/config.rs
blob: 4563f34865b6aad384df182240bde00366a566d3 (plain) (blame)
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
use std::net::SocketAddr;
use std::path::{Path, PathBuf};

use eyre::Context;
use tap::Pipe;

#[derive(serde::Deserialize)]
pub struct Config {
    pub web_socket: SocketAddr,
    pub web_base: String,
    pub cookie_domain: Option<String>,
    pub admin_socket: PathBuf,
    pub data: PathBuf,
}

impl Config {
    pub fn load(path: &Path) -> eyre::Result<Self> {
        let mut config: Config = path
            .pipe(std::fs::read_to_string)
            .wrap_err("reading config file")?
            .as_str()
            .pipe(toml::from_str)
            .wrap_err("parsing config file")?;
        if config.web_base.ends_with('/') {
            config.web_base = config.web_base.trim_end_matches('/').to_string();
        }
        Ok(config)
    }
}