Ferrit Explore
中文·繁體·EN·日本語 Sign in Register
cielxl / veld / src / config / mod.rs
pub mod ast;
pub mod directives;
pub mod parser;

pub use ast::{Block, Config, Directive, Value};
pub use directives::{LocationConfig, LocationMatch, ParsedConfig, ServerConfig};
pub use parser::{parse, ConfigError};

use std::path::Path;

/// Load and parse a configuration file
pub fn load_config(path: &Path) -> Result<ParsedConfig, ConfigError> {
    let content = std::fs::read_to_string(path).map_err(|e| ConfigError {
        line: 0,
        message: format!("Failed to read config: {}", e),
    })?;

    let ast = parse(&content)?;
    let config = directives::interpret(&ast)?;
    Ok(config)
}

/// Test configuration file syntax
pub fn test_config(path: &Path) -> Result<(), ConfigError> {
    load_config(path)?;
    Ok(())
}