omni_director/core/
config.rs1use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct SystemConfig {
11 pub server: ServerConfig,
13 pub providers: ProviderConfig,
15 pub features: FeatureConfig,
17 pub logging: LoggingConfig,
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct ServerConfig {
24 pub host: String,
26 pub port: u16,
28 pub workers: usize,
30 pub timeout: u64,
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36pub struct ProviderConfig {
37 pub providers_dir: String,
39 pub auto_discovery: bool,
41 pub settings: HashMap<String, serde_json::Value>,
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct FeatureConfig {
48 pub features_dir: String,
50 pub auto_discovery: bool,
52 pub settings: HashMap<String, serde_json::Value>,
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct LoggingConfig {
59 pub level: String,
61 pub timestamps: bool,
63 pub format: String,
65}
66
67impl Default for SystemConfig {
68 fn default() -> Self {
69 Self {
70 server: ServerConfig {
71 host: "0.0.0.0".to_string(),
72 port: 8081,
73 workers: 32,
74 timeout: 30,
75 },
76 providers: ProviderConfig {
77 providers_dir: "./providers".to_string(),
78 auto_discovery: true,
79 settings: HashMap::new(),
80 },
81 features: FeatureConfig {
82 features_dir: "./features".to_string(),
83 auto_discovery: true,
84 settings: HashMap::new(),
85 },
86 logging: LoggingConfig {
87 level: "info".to_string(),
88 timestamps: true,
89 format: "human".to_string(),
90 },
91 }
92 }
93}
94
95impl SystemConfig {
96 pub fn load() -> Result<Self, Box<dyn std::error::Error>> {
98 if let Ok(content) = std::fs::read_to_string("omni-director.toml") {
100 return Ok(toml::from_str(&content)?);
101 }
102
103 let mut config = Self::default();
105
106 if let Ok(host) = std::env::var("OMNI_HOST") {
107 config.server.host = host;
108 }
109
110 if let Ok(port) = std::env::var("OMNI_PORT") {
111 config.server.port = port.parse().unwrap_or(8081);
112 }
113
114 if let Ok(providers_dir) = std::env::var("OMNI_PROVIDERS_DIR") {
115 config.providers.providers_dir = providers_dir;
116 }
117
118 if let Ok(features_dir) = std::env::var("OMNI_FEATURES_DIR") {
119 config.features.features_dir = features_dir;
120 }
121
122 Ok(config)
123 }
124}