Skip to main content

Module config

Module config 

Source
Expand description

Configuration for the Hammerwork web dashboard.

This module provides comprehensive configuration options for the web dashboard, including server settings, authentication, WebSocket configuration, and more.

§Examples

§Basic Configuration

use hammerwork_web::config::DashboardConfig;

let config = DashboardConfig::new()
    .with_bind_address("127.0.0.1", 8080)
    .with_database_url("postgresql://localhost/hammerwork");

assert_eq!(config.bind_addr(), "127.0.0.1:8080");

§Configuration with Authentication

use hammerwork_web::config::{DashboardConfig, AuthConfig};
use std::time::Duration;

let config = DashboardConfig::new()
    .with_auth("admin", "$2b$12$hash...")
    .with_cors(true);

assert!(config.auth.enabled);
assert_eq!(config.auth.username, "admin");
assert!(config.enable_cors);

§Loading from File

use hammerwork_web::config::DashboardConfig;

// Create a configuration file (dashboard.toml)
let config_content = r#"
bind_address = "0.0.0.0"
port = 9090
database_url = "postgresql://localhost/hammerwork"
enable_cors = true

[auth]
enabled = true
username = "admin"
"#;

std::fs::write("dashboard.toml", config_content)?;

// Load the configuration
let config = DashboardConfig::from_file("dashboard.toml")?;
assert_eq!(config.port, 9090);
assert!(config.enable_cors);

// Clean up
std::fs::remove_file("dashboard.toml")?;

Structs§

AuthConfig
Authentication configuration for the web dashboard.
DashboardConfig
Main configuration for the web dashboard.
WebSocketConfig
WebSocket configuration