pub mod env;
pub mod providers;
pub mod repository;
pub use env::{env, env_optional, env_required, load_dotenv, Environment};
pub use providers::{
AppConfig, AppConfigBuilder, LangConfig, LangConfigBuilder, ServerConfig, ServerConfigBuilder,
};
use std::path::Path;
pub struct Config;
impl Config {
pub fn init(project_root: &Path) -> Environment {
let env = env::load_dotenv(project_root);
repository::register(AppConfig::from_env());
repository::register(ServerConfig::from_env());
repository::register(LangConfig::from_env());
env
}
pub fn get<T: std::any::Any + Send + Sync + Clone + 'static>() -> Option<T> {
repository::get::<T>()
}
pub fn register<T: std::any::Any + Send + Sync + 'static>(config: T) {
repository::register(config);
}
pub fn has<T: std::any::Any + 'static>() -> bool {
repository::has::<T>()
}
pub fn environment() -> Environment {
Config::get::<AppConfig>()
.map(|c| c.environment)
.unwrap_or_else(Environment::detect)
}
pub fn is_production() -> bool {
Self::environment().is_production()
}
pub fn is_development() -> bool {
Self::environment().is_development()
}
pub fn is_debug() -> bool {
Config::get::<AppConfig>().map(|c| c.debug).unwrap_or(true)
}
}