mirror of
				https://github.com/csehviktor/status-monitor.git
				synced 2025-08-08 18:06:14 +02:00 
			
		
		
		
	add config for agent
This commit is contained in:
		
							
								
								
									
										27
									
								
								agent/src/config.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								agent/src/config.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| use serde::{Deserialize, Serialize}; | ||||
|  | ||||
| const CONFIG_PATH: &str = if cfg!(debug_assertions) { | ||||
|     "agent/config.toml" | ||||
| } else { | ||||
|     "config.toml" | ||||
| }; | ||||
|  | ||||
| #[derive(Serialize, Deserialize)] | ||||
| pub struct MqttConfig { | ||||
|     pub agent: String, | ||||
|     pub host: String, | ||||
|     pub port: u16, | ||||
| } | ||||
|  | ||||
| #[derive(Serialize, Deserialize)] | ||||
| pub struct Config { | ||||
|     pub send_interval_seconds: u64, | ||||
|     pub mqtt: MqttConfig, | ||||
| } | ||||
|  | ||||
| pub fn load_config() -> anyhow::Result<Config> { | ||||
|     let file = std::fs::read_to_string(CONFIG_PATH)?; | ||||
|     let config: Config = toml::from_str(&file)?; | ||||
|  | ||||
|     Ok(config) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user