config_mod - OmniCloudOrg/OmniOrchestrator GitHub Wiki
Path: src/config/mod.rs
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>,
}
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.
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,
}
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.
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,
}
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.
pub fn read() -> Result<Self, ConfigError> {
let config_path = "config.json";
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.
-
Ok(ServerConfig)
- Successfully loaded or created configuration -
Err(ConfigError)
- Failed to parse existing configuration
- If the file doesn't exist, creates a default configuration - If the file exists but can't be parsed, returns a ParseError
pub fn write(&self) -> Result<(), ConfigError> {
let config_path = "config.json";
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.
-
Ok(())
- Successfully wrote configuration to file -
Err(ConfigError)
- Failed to serialize or write configuration
- Returns ParseError if serialization to JSON fails - Returns FailedToWrite if writing to the file fails
pub fn write_default() -> Result<(), ConfigError> {
let config = ServerConfig::default();
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.
-
Ok(())
- Successfully wrote default configuration to file -
Err(ConfigError)
- Failed to write default configuration