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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
use config::File;
use serde::Deserialize;
use crate::auth;
#[derive(Debug, Clone, Deserialize)]
#[serde(default)]
pub struct Config {
pub serveraddr: String,
pub pingtimeout: i64,
pub pingthreshold: u64,
pub auth: Auth,
}
impl Default for Config {
fn default() -> Self {
Self {
serveraddr: "0.0.0.0:7229".to_string(),
pingtimeout: 10,
pingthreshold: 1,
auth: Default::default(),
}
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct Auth {
pub method: auth::Methods,
pub secret: String,
}
impl Default for Auth {
fn default() -> Self {
Self {
method: auth::Methods::None,
secret: String::new(),
}
}
}
impl Config {
pub fn load() -> Result<Self, config::ConfigError> {
let config = config::Config::builder()
.add_source(File::with_name("/etc/webol").required(false))
.add_source(File::with_name("config.toml").required(false))
.add_source(config::Environment::with_prefix("WEBOL").separator("_"))
.build()?;
config.try_deserialize()
}
}
|