use std::fs; use log::error; use once_cell::sync::Lazy; use serde::{Serialize, Deserialize}; pub static CONFIG: Lazy = Lazy::new(|| { let config_str = match fs::read_to_string("/etc/trifid/config.toml") { Ok(str) => str, Err(e) => { error!("Unable to read config file: {}", e); std::process::exit(1); } }; match toml::from_str(&config_str) { Ok(cfg) => cfg, Err(e) => { error!("Unable to parse config file: {}", e); std::process::exit(1); } } }); #[derive(Serialize, Debug, Deserialize)] pub struct TrifidConfig { pub database: TrifidConfigDatabase } #[derive(Serialize, Deserialize, Debug)] pub struct TrifidConfigDatabase { pub url: String, #[serde(default = "max_connections_default")] pub max_connections: u32, #[serde(default = "min_connections_default")] pub min_connections: u32, #[serde(default = "time_defaults")] pub connect_timeout: u64, #[serde(default = "time_defaults")] pub acquire_timeout: u64, #[serde(default = "time_defaults")] pub idle_timeout: u64, #[serde(default = "time_defaults")] pub max_lifetime: u64, #[serde(default = "sqlx_logging_default")] pub sqlx_logging: bool } fn max_connections_default() -> u32 { 100 } fn min_connections_default() -> u32 { 5 } fn time_defaults() -> u64 { 8 } fn sqlx_logging_default() -> bool { true }