use anyhow::{Context, Result};
use once_cell::sync::OnceCell;
use crate::Config;
static GLOBAL_CONFIG: OnceCell<Config> = OnceCell::new();
pub fn load_from_env() -> Result<&'static Config> {
GLOBAL_CONFIG.get_or_try_init(|| {
let mut config = Config::from_env().context("Failed to load configuration")?;
if let Err(err) = config.apply_env_overrides() {
tracing::warn!(error = %err, "Failed to apply environment overrides; continuing with base config");
}
Ok(config)
})
}
pub fn get() -> &'static Config {
GLOBAL_CONFIG
.get()
.expect("Config not initialized; call load_from_env first")
}