config_mod - OmniCloudOrg/OmniOrchestrator GitHub Wiki

mod (src/config)

Path: src/config/mod.rs

Table of Contents

Public Items

struct ServerConfig

Definition

pub struct ServerConfig {
    /// The port number on which the server will listen
    pub port: u16,
    
    /// The IP address to which the server will bind
    pub address: String,
    
    /// Whether to apply syntax highlighting to SQL logs
    pub highlight_sql: bool,
    
    /// List of other server instances in the cluster
    pub instances: Vec<Instance>,
}

Documentation

Configuration for the OmniOrchestrator server application. This structure defines all the configurable parameters for the server, including network settings and behavior options. It supports serialization to and deserialization from JSON for persistent configuration. The configuration can be loaded from a file or generated with default values if no configuration file exists.

struct Instance

Definition

pub struct Instance {
    /// The port number on which the instance is listening
    pub port: u16,
    
    /// The hostname or IP address of the instance
    pub address: String,
}

Documentation

Represents an instance of the server in the cluster. This structure contains the network location information for a server instance that is part of the OmniOrchestrator cluster. It's used for peer discovery and communication between cluster nodes.

enum ConfigError

Definition

pub enum ConfigError {
    /// Indicates that the configuration file could not be found
    FileNotFound,
    
    /// Indicates that writing to the configuration file failed
    FailedToWrite,
    
    /// Indicates that parsing the configuration file content failed
    ParseError,
}

Documentation

Possible errors that can occur during configuration operations. This enum represents the various error conditions that might arise when reading from or writing to the configuration file.

fn read

Definition

    pub fn read() -> Result<Self, ConfigError> {
        let config_path = "config.json";

Documentation

Reads the server configuration from the config file. Attempts to load the configuration from "config.json" in the current directory. If the file doesn't exist or can't be read, it creates a new configuration file with default values and returns those defaults.

Returns
  • Ok(ServerConfig) - Successfully loaded or created configuration
  • Err(ConfigError) - Failed to parse existing configuration
Error Handling
  • If the file doesn't exist, creates a default configuration - If the file exists but can't be parsed, returns a ParseError

fn write

Definition

    pub fn write(&self) -> Result<(), ConfigError> {
        let config_path = "config.json";

Documentation

Writes the current configuration to the config file. Serializes the configuration to JSON and writes it to "config.json" in the current directory. This allows configuration changes to persist across server restarts.

Returns
  • Ok(()) - Successfully wrote configuration to file
  • Err(ConfigError) - Failed to serialize or write configuration
Error Handling
  • Returns ParseError if serialization to JSON fails - Returns FailedToWrite if writing to the file fails

fn write_default

Definition

    pub fn write_default() -> Result<(), ConfigError> {
        let config = ServerConfig::default();

Documentation

Creates and writes a default configuration to the config file. This is a convenience method that creates a ServerConfig with default values and writes it to the configuration file. It's typically used when no configuration file exists yet.

Returns
  • Ok(()) - Successfully wrote default configuration to file
  • Err(ConfigError) - Failed to write default configuration
⚠️ **GitHub.com Fallback** ⚠️