peach-workspace/peach-web/src/config.rs

32 lines
944 B
Rust
Raw Normal View History

//! Define the configuration parameters for the web application.
//!
//! These configs are loaded using peach-lib::config_manager which checks config keys from
//! three sources:
//! 1. from environmental variables
//! 2. from a configuration file
//! 3. from default values
use crate::error::PeachWebError;
2022-05-12 09:26:23 +00:00
use peach_lib::config_manager::get_config_value;
2022-05-12 09:26:23 +00:00
pub struct RouilleConfig {
pub standalone_mode: bool,
pub disable_auth: bool,
pub addr: String,
pub port: String,
}
2022-05-12 09:26:23 +00:00
impl RouilleConfig {
pub fn new() -> Result<RouilleConfig, PeachWebError> {
// define default config values
let config = RouilleConfig {
standalone_mode: get_config_value("STANDALONE_MODE")?.as_str() == "true",
disable_auth: get_config_value("DISABLE_AUTH")?.as_str() == "true",
addr: get_config_value("ADDR")?,
port: get_config_value("PORT")?,
};
Ok(config)
}
}