blob: 31d1e1fe664a16b81b337f9a277ad52f76883b26 (
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
30
31
|
use std::net::SocketAddr;
use std::path::{Path, PathBuf};
use cursive::reexports::ahash::HashSet;
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 handoffs: HashSet<String>,
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)
}
}
|