diff options
author | FxQnLr <[email protected]> | 2024-02-12 16:00:45 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2024-02-12 16:00:45 +0100 |
commit | c663810817183c8f92a4279236ca84d271365088 (patch) | |
tree | 0c844cc883e5e474a9cdad30004108852f13f903 /src/config.rs | |
parent | da6367885d31698464e1bec122e3e673974427c6 (diff) | |
parent | 9139d76cb1cf462820b2ddfa80d9a8d55bb30996 (diff) | |
download | webol-c663810817183c8f92a4279236ca84d271365088.tar webol-c663810817183c8f92a4279236ca84d271365088.tar.gz webol-c663810817183c8f92a4279236ca84d271365088.zip |
Merge pull request #14 from FxQnLr/axum7
Axum7 & config changes
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/config.rs b/src/config.rs index 4c79810..4319ffc 100644 --- a/src/config.rs +++ b/src/config.rs | |||
@@ -1,11 +1,25 @@ | |||
1 | use config::Config; | 1 | use config::File; |
2 | use once_cell::sync::Lazy; | 2 | use serde::Deserialize; |
3 | 3 | ||
4 | pub static SETTINGS: Lazy<Config> = Lazy::new(setup); | 4 | #[derive(Debug, Clone, Deserialize)] |
5 | pub struct Config { | ||
6 | pub database_url: String, | ||
7 | pub apikey: String, | ||
8 | pub serveraddr: String, | ||
9 | pub pingtimeout: i64, | ||
10 | } | ||
11 | |||
12 | impl Config { | ||
13 | pub fn load() -> Result<Self, config::ConfigError> { | ||
14 | let config = config::Config::builder() | ||
15 | .set_default("serveraddr", "0.0.0.0:7229")? | ||
16 | .set_default("pingtimeout", 10)? | ||
17 | .add_source(File::with_name("config.toml").required(false)) | ||
18 | .add_source(File::with_name("config.dev.toml").required(false)) | ||
19 | .add_source(config::Environment::with_prefix("WEBOL").prefix_separator("_")) | ||
20 | .build()?; | ||
21 | |||
22 | config.try_deserialize() | ||
23 | } | ||
24 | } | ||
5 | 25 | ||
6 | fn setup() -> Config { | ||
7 | Config::builder() | ||
8 | .add_source(config::Environment::with_prefix("WEBOL").separator("_")) | ||
9 | .build() | ||
10 | .unwrap() | ||
11 | } \ No newline at end of file | ||