use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
pub server: ServerConfig,
pub database: DatabaseConfig,
pub search: SearchConfig,
pub matching: MatchingConfig,
pub observability: ObservabilityConfig,
pub streaming: StreamingConfig,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServerConfig {
pub host: String,
pub port: u16,
pub grpc_port: u16,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DatabaseConfig {
pub url: String,
pub max_connections: u32,
pub min_connections: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SearchConfig {
pub index_path: String,
pub cache_size_mb: usize,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MatchingConfig {
pub threshold_score: f64,
pub exact_match_score: f64,
pub fuzzy_match_score: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ObservabilityConfig {
pub service_name: String,
pub otlp_endpoint: String,
pub log_level: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StreamingConfig {
pub broker_url: String,
pub topic: String,
}
impl Default for Config {
fn default() -> Self {
Self {
server: ServerConfig {
host: "0.0.0.0".to_string(),
port: 8080,
grpc_port: 50051,
},
database: DatabaseConfig {
url: "postgres://localhost/event_service".to_string(),
max_connections: 10,
min_connections: 2,
},
search: SearchConfig {
index_path: "./data/search_index".to_string(),
cache_size_mb: 512,
},
matching: MatchingConfig {
threshold_score: 0.85,
exact_match_score: 1.0,
fuzzy_match_score: 0.8,
},
observability: ObservabilityConfig {
service_name: "event-service".to_string(),
otlp_endpoint: "http://localhost:4317".to_string(),
log_level: "info".to_string(),
},
streaming: StreamingConfig {
broker_url: "localhost:9003".to_string(),
topic: "event-events".to_string(),
},
}
}
}
impl Config {
pub fn from_env() -> crate::Result<Self> {
dotenvy::dotenv().ok();
Ok(Self::default())
}
}