This commit is contained in:
Mateusz Gruszczyński
2026-07-22 11:15:01 +02:00
parent 1be2023e36
commit 8bf45938ea
19 changed files with 189 additions and 33 deletions
+10
View File
@@ -12,6 +12,7 @@ pub struct Config {
pub asset_version: String,
pub smtp: Option<crate::state::SmtpConfig>,
pub registration_enabled: bool,
pub frontend_log_level: String,
}
impl Config {
@@ -56,6 +57,7 @@ impl Config {
asset_version: env_var("ASSET_VERSION", env!("CARGO_PKG_VERSION")),
smtp,
registration_enabled: env_bool("REGISTRATION_ENABLED", false)?,
frontend_log_level: env_log_level("FRONTEND_LOG_LEVEL", "warn")?,
})
}
}
@@ -74,3 +76,11 @@ fn env_bool(name: &str, default: bool) -> Result<bool, Box<dyn std::error::Error
Err(_) => Ok(default),
}
}
fn env_log_level(name: &str, default: &str) -> Result<String, Box<dyn std::error::Error>> {
let value = env_var(name, default).trim().to_ascii_lowercase();
match value.as_str() {
"off" | "error" | "warn" | "info" | "debug" => Ok(value),
_ => Err(format!("{name} must be one of: off, error, warn, info, debug").into()),
}
}