forked from PeachCloud/peach-workspace
32 lines
940 B
Rust
32 lines
940 B
Rust
//! 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;
|
|
use peach_lib::config_manager::get_config_value;
|
|
|
|
pub struct ServerConfig {
|
|
pub standalone_mode: bool,
|
|
pub disable_auth: bool,
|
|
pub addr: String,
|
|
pub port: String,
|
|
}
|
|
|
|
impl ServerConfig {
|
|
pub fn new() -> Result<ServerConfig, PeachWebError> {
|
|
// define default config values
|
|
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)
|
|
}
|
|
}
|