pipey 0.1.1

A lightweight HTTP-to-WebSocket event delivery service.
Documentation
use std::env;

/// Validates that all required environment variables are set and non-empty.
///
/// This function ensures the application has all necessary configuration
/// before starting.
///
/// # Required Variables
/// - `REDIS_URL`
/// - `HOST`
/// - `PORT`
/// - `API_VERSION`
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()
    );
}