use std::env;
fn check_env() -> Result<(), String> {
const REQUIRED: &[&str] = &["REDIS_URL", "HOST", "PORT", "API_VERSION"];
let missing: Vec<&str> = REQUIRED
.iter()
.copied()
.filter(|key| match env::var(key) {
Ok(value) => value.trim().is_empty(),
Err(_) => true,
})
.collect();
if missing.is_empty() {
Ok(())
} else {
Err(format!(
"Missing required environment variable(s): {}",
missing.join(", ")
))
}
}
pub fn init_check_env() {
use colored::Colorize;
if let Err(err) = check_env() {
eprintln!(
"{} Invalid configuration detected",
"[CONFIG ERROR]".red().bold()
);
eprintln!("{} {}", "[DETAILS]".yellow().bold(), err);
std::process::exit(1);
}
println!(
"{} Configuration validated successfully",
"[OK]".green().bold()
);
}