mirror of
https://github.com/ZeusWPI/ZNS.git
synced 2024-10-30 13:34:26 +01:00
29 lines
611 B
Rust
29 lines
611 B
Rust
|
use std::{env, sync::OnceLock};
|
||
|
|
||
|
use dotenvy::dotenv;
|
||
|
|
||
|
static CONFIG: OnceLock<Config> = OnceLock::new();
|
||
|
|
||
|
pub struct Config {
|
||
|
pub zauth_url: String,
|
||
|
pub db_uri: String,
|
||
|
}
|
||
|
|
||
|
impl Config {
|
||
|
pub fn initialize() {
|
||
|
assert!(CONFIG.get().is_none());
|
||
|
|
||
|
Config::get();
|
||
|
}
|
||
|
|
||
|
pub fn get() -> &'static Config {
|
||
|
CONFIG.get_or_init(|| {
|
||
|
dotenv().ok();
|
||
|
Config {
|
||
|
db_uri: env::var("DATABASE_URL").expect("DATABASE_URL must be set"),
|
||
|
zauth_url: env::var("ZAUTH_URL").expect("ZAUTH_URL must be set"),
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|