use crate::AppConfig;
use config::Config as ProxyConfig;
use std::sync::OnceLock;
static INITIAL_APP_CONFIG: OnceLock<AppConfig> = OnceLock::new();
static INITIAL_PROXY_CONFIG: OnceLock<ProxyConfig> = OnceLock::new();
pub(crate) struct StaticInitialConfig;
impl StaticInitialConfig {
pub(crate) fn app_config() -> &'static AppConfig {
INITIAL_APP_CONFIG.get().expect(
"the initial application configuration should not be accessed before initialization",
)
}
pub(crate) fn proxy_config() -> &'static ProxyConfig {
INITIAL_PROXY_CONFIG
.get()
.expect("the initial proxy configuration should not be accessed before initialization")
}
pub(crate) fn seed(proxy_config: ProxyConfig) {
let app_config = proxy_config
.clone()
.try_deserialize::<AppConfig>()
.expect("it should be possible to deserialize the initial application configuration");
INITIAL_PROXY_CONFIG
.set(proxy_config)
.expect("the initial proxy configuration should not be set more than once");
INITIAL_APP_CONFIG
.set(app_config)
.expect("the initial application configuration should not be set more than once");
}
}