francoisgib_webserver 1.0.3

HTTP Webserver
Documentation
use serde::Deserialize;

// Headers
pub const PRE_ALLOCATED_RESPONSE_HEADERS: usize = 4;
pub const PRE_ALLOCATED_REQUEST_HEADERS: usize = 8;

// Buffer
pub const PRE_ALLOCATED_BUFFER_SIZE: usize = 1024;

pub const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
pub const CARGO_PKG_NAME: &str = env!("CARGO_PKG_NAME");

#[derive(Debug, Deserialize, Default)]
pub struct Config {
    pub server: ServerConfig,
    pub pool: PoolConfig,
}

#[derive(Debug, Deserialize)]
pub struct ServerConfig {
    pub name: Option<String>,
    pub hostname: Option<String>,
    pub port: u16,
    pub log_file: Option<String>,
    pub log_level: Option<u8>,
    pub debug: Option<bool>,
    pub not_found_endpoint_path: Option<String>,
    pub metrics_endpoint: Option<String>,
}

impl ServerConfig {
    pub fn new(
        name: Option<String>,
        hostname: Option<String>,
        port: u16,
        log_file: Option<String>,
        log_level: Option<u8>,
        debug: Option<bool>,
        not_found_endpoint_path: Option<String>,
        metrics_endpoint: Option<String>,
    ) -> Self {
        Self {
            name: name.to_owned(),
            hostname,
            port,
            log_file,
            log_level,
            debug,
            not_found_endpoint_path,
            metrics_endpoint,
        }
    }
}

impl Default for ServerConfig {
    fn default() -> Self {
        Self {
            name: None,
            hostname: None,
            port: 8080,
            log_file: None,
            log_level: Some(1),
            debug: None,
            not_found_endpoint_path: None,
            metrics_endpoint: None,
        }
    }
}

#[derive(Debug, Deserialize, Default)]
pub struct PoolConfig {
    pub worker_threads: Option<usize>,
}