summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2024-02-12 15:05:03 +0100
committerGitHub <[email protected]>2024-02-12 15:05:03 +0100
commitca395b81bcadb9dde9214098f2cab0c7a3561574 (patch)
tree055bae9ef4e65f53b826b240f0b8e3b15b73693e /src/config.rs
parente4832b4cf36ba0eaed298ee458498eddd7176590 (diff)
parente50a868f69b602cc0bc84d51e9940878924f49ef (diff)
downloadwebol-ca395b81bcadb9dde9214098f2cab0c7a3561574.tar
webol-ca395b81bcadb9dde9214098f2cab0c7a3561574.tar.gz
webol-ca395b81bcadb9dde9214098f2cab0c7a3561574.zip
Merge pull request #13 from FxQnLr/config
Config
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/config.rs b/src/config.rs
index 4c79810..e88ddab 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,11 +1,25 @@
1use config::Config; 1use config::File;
2use once_cell::sync::Lazy; 2use serde::Deserialize;
3 3
4pub static SETTINGS: Lazy<Config> = Lazy::new(setup); 4#[derive(Debug, Clone, Deserialize)]
5pub struct Config {
6 pub database_url: String,
7 pub apikey: String,
8 pub serveraddr: String,
9 pub pingtimeout: i64,
10}
11
12impl 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").separator("_"))
20 .build()?;
21
22 config.try_deserialize()
23 }
24}
5 25
6fn 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