diff options
| author | Fuwn <[email protected]> | 2021-04-27 17:02:09 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-04-27 17:02:09 +0000 |
| commit | fc5c05bce7a5f9d763d72b870717a530dfcf9524 (patch) | |
| tree | a9112c07c3cef656be38715cf143797529fbdbb2 /src/config/mod.rs | |
| parent | etc: Add a Say Thanks button :) (diff) | |
| download | whirl-fc5c05bce7a5f9d763d72b870717a530dfcf9524.tar.xz whirl-fc5c05bce7a5f9d763d72b870717a530dfcf9524.zip | |
feature: New configuration file format
Diffstat (limited to 'src/config/mod.rs')
| -rw-r--r-- | src/config/mod.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs new file mode 100644 index 0000000..f57335d --- /dev/null +++ b/src/config/mod.rs @@ -0,0 +1,38 @@ +// Copyleft 2021-2021 Whirlsplash +// SPDX-License-Identifier: GPL-3.0-only + +use config::{ConfigError, File}; +use serde::Deserialize; +use serde_derive::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Debug)] +pub struct WhirlsplashConfig { + pub worldsmaster_username: String, + pub log_level: i64, +} +#[derive(Serialize, Deserialize, Debug)] +pub struct DistributorConfig { + pub worldsmaster_greeting: String, + pub port: i64, +} +#[derive(Serialize, Deserialize, Debug)] +pub struct HubConfig { + pub port: i64, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Config { + pub whirlsplash: WhirlsplashConfig, + pub distributor: DistributorConfig, + pub hub: HubConfig, +} +impl Config { + fn load() -> Result<Self, ConfigError> { + let mut s = config::Config::new(); + + s.merge(File::with_name("./Whirl.toml").required(false))?; + s.try_into() + } + + pub fn get() -> Result<Self, ConfigError> { Self::load() } +} |