mod loader;
mod sections;
pub use loader::ConfigError;
pub use sections::{
AdminSettings, AuditSettings, AuthSettings, BrandSettings, CacheSettings, DatabaseSettings,
JobsSettings, JwtSettings, LoggingSettings, MailSettings, RoutesSettings, SecuritySettings,
ServerSettings, Settings, TenancySettings,
};
impl Settings {
pub fn load(env: &str) -> Result<Self, ConfigError> {
loader::load_with_root(std::path::Path::new("config"), env)
}
pub fn load_from(root: &std::path::Path, env: &str) -> Result<Self, ConfigError> {
loader::load_with_root(root, env)
}
pub fn load_from_env() -> Result<Self, ConfigError> {
let env = current_env_tier();
loader::load_with_root(std::path::Path::new("config"), &env)
}
#[must_use]
pub fn current_env_tier() -> String {
current_env_tier()
}
}
fn current_env_tier() -> String {
std::env::var("RUSTANGO_ENV")
.ok()
.filter(|s| !s.is_empty())
.unwrap_or_else(|| "dev".to_owned())
}
#[cfg(test)]
mod tier_tests {
use super::*;
#[test]
fn current_env_tier_defaults_to_dev_when_unset() {
if std::env::var("RUSTANGO_ENV").is_err() {
assert_eq!(Settings::current_env_tier(), "dev");
}
}
}