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

32 lines
940 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 10:21:05 +00:00
pub struct ServerConfig {
pub standalone_mode: bool,
pub disable_auth: bool,
pub addr: String,
pub port: String,
}
2022-05-12 10:21:05 +00:00
impl ServerConfig {
pub fn new() -> Result<ServerConfig, PeachWebError> {
// define default config values
2022-05-12 10:21:05 +00:00
let config = ServerConfig {
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)
}
}