use colored::*;
use std::sync::Once;
static INIT_ENV: Once = Once::new();
pub fn initialize_env() {
INIT_ENV.call_once(|| {
if dotenvy::dotenv().is_ok() {
println!(
"{}",
"[CONFIG] Successfully loaded .env configurations into memory."
.bold()
.green()
);
} else {
println!(
"{}",
"[CONFIG] No .env file detected. Falling back to system environment variables."
.bold()
.yellow()
);
}
});
}
pub fn get_env(key: &str, default: &str) -> String {
initialize_env();
match std::env::var(key) {
Ok(val) => val, Err(_) => {
default.to_string()
}
}
}