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 | |
| 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')
| -rw-r--r-- | src/config/Whirl.default.toml | 10 | ||||
| -rw-r--r-- | src/config/mod.rs | 38 |
2 files changed, 48 insertions, 0 deletions
diff --git a/src/config/Whirl.default.toml b/src/config/Whirl.default.toml new file mode 100644 index 0000000..688fa88 --- /dev/null +++ b/src/config/Whirl.default.toml @@ -0,0 +1,10 @@ +[whirlsplash] +worldsmaster_username = "WORLDSMASTER" # DO NOT CHANGE UNLESS YOU KNOW WHAT YOU ARE DOING +log_level = 1 # Generally, you should only change this if you are expiriencing issues + +[distributor] +worldsmaster_greeting = "Welcome to Whirlsplash!" +port = 6650 # DO NOT CHANGE UNLESS YOU KNOW WHAT YOU ARE DOING + +[hub] +port = 5673 # DO NOT CHANGE UNLESS YOU KNOW WHAT YOU ARE DOING 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() } +} |