mod env;
mod errors;
mod help;
#[cfg(test)]
mod tests;
use lora_database::SyncMode;
pub use env::{resolve, resolve_from_process, EnvInputs};
pub use errors::ConfigError;
pub use help::{help_text, version_text};
pub const DEFAULT_HOST: &str = "127.0.0.1";
pub const DEFAULT_PORT: u16 = 4747;
pub const HOST_ENV: &str = "LORA_SERVER_HOST";
pub const PORT_ENV: &str = "LORA_SERVER_PORT";
pub const SNAPSHOT_PATH_ENV: &str = "LORA_SERVER_SNAPSHOT_PATH";
pub const WAL_DIR_ENV: &str = "LORA_SERVER_WAL_DIR";
pub const WAL_SYNC_MODE_ENV: &str = "LORA_SERVER_WAL_SYNC_MODE";
pub const DEFAULT_WAL_SEGMENT_TARGET_BYTES: u64 = 8 * 1024 * 1024;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ServerConfig {
pub host: String,
pub port: u16,
pub snapshot_path: Option<std::path::PathBuf>,
pub restore_from: Option<std::path::PathBuf>,
pub wal_dir: Option<std::path::PathBuf>,
pub wal_sync_mode: SyncMode,
}
impl Default for ServerConfig {
fn default() -> Self {
Self {
host: DEFAULT_HOST.to_string(),
port: DEFAULT_PORT,
snapshot_path: None,
restore_from: None,
wal_dir: None,
wal_sync_mode: SyncMode::default(),
}
}
}
impl ServerConfig {
pub fn bind_addr(&self) -> String {
if self.host.contains(':') && !self.host.starts_with('[') {
format!("[{}]:{}", self.host, self.port)
} else {
format!("{}:{}", self.host, self.port)
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ConfigOutcome {
Run(ServerConfig),
Help(String),
Version(String),
}