diff options
author | fxqnlr <[email protected]> | 2024-10-06 15:45:09 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2024-10-06 15:45:09 +0200 |
commit | 7740bf12633a3c7c2e461aa8b74c852efbb9318b (patch) | |
tree | 9d4f048540c123c0ca6426acdeb8f56c7083978c /src/config.rs | |
parent | 843414433d68b7a7d1b60f814621766bcfca2206 (diff) | |
parent | ae386a491b23cfbadc4da8680c8ebcb85310dcb5 (diff) | |
download | webol-main.tar webol-main.tar.gz webol-main.zip |
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/config.rs b/src/config.rs index 18c3bab..2e9c1eb 100644 --- a/src/config.rs +++ b/src/config.rs | |||
@@ -4,30 +4,45 @@ use serde::Deserialize; | |||
4 | use crate::auth; | 4 | use crate::auth; |
5 | 5 | ||
6 | #[derive(Debug, Clone, Deserialize)] | 6 | #[derive(Debug, Clone, Deserialize)] |
7 | #[serde(default)] | ||
7 | pub struct Config { | 8 | pub struct Config { |
8 | pub serveraddr: String, | 9 | pub addr: String, |
9 | pub pingtimeout: i64, | 10 | pub pingtimeout: i64, |
10 | pub pingthreshold: u64, | 11 | pub pingthreshold: u64, |
11 | pub auth: Auth, | 12 | pub auth: Auth, |
12 | } | 13 | } |
13 | 14 | ||
15 | impl Default for Config { | ||
16 | fn default() -> Self { | ||
17 | Self { | ||
18 | addr: "0.0.0.0:7229".to_string(), | ||
19 | pingtimeout: 10, | ||
20 | pingthreshold: 1, | ||
21 | auth: Default::default(), | ||
22 | } | ||
23 | } | ||
24 | } | ||
25 | |||
14 | #[derive(Debug, Clone, Deserialize)] | 26 | #[derive(Debug, Clone, Deserialize)] |
15 | pub struct Auth { | 27 | pub struct Auth { |
16 | pub method: auth::Methods, | 28 | pub method: auth::Methods, |
17 | pub secret: String, | 29 | pub secret: String, |
18 | } | 30 | } |
19 | 31 | ||
32 | impl Default for Auth { | ||
33 | fn default() -> Self { | ||
34 | Self { | ||
35 | method: auth::Methods::None, | ||
36 | secret: String::new(), | ||
37 | } | ||
38 | } | ||
39 | } | ||
40 | |||
20 | impl Config { | 41 | impl Config { |
21 | pub fn load() -> Result<Self, config::ConfigError> { | 42 | pub fn load() -> Result<Self, config::ConfigError> { |
22 | let config = config::Config::builder() | 43 | let config = config::Config::builder() |
23 | .set_default("serveraddr", "0.0.0.0:7229")? | 44 | .add_source(File::with_name("/etc/webol").required(false)) |
24 | .set_default("pingtimeout", 10)? | ||
25 | .set_default("pingthreshold", 1)? | ||
26 | .set_default("timeoffset", 0)? | ||
27 | .set_default("auth.method", "none")? | ||
28 | .set_default("auth.secret", "")? | ||
29 | .add_source(File::with_name("config.toml").required(false)) | 45 | .add_source(File::with_name("config.toml").required(false)) |
30 | .add_source(File::with_name("config.dev.toml").required(false)) | ||
31 | .add_source(config::Environment::with_prefix("WEBOL").separator("_")) | 46 | .add_source(config::Environment::with_prefix("WEBOL").separator("_")) |
32 | .build()?; | 47 | .build()?; |
33 | 48 | ||