changed configuration hierarchie

This commit is contained in:
2025-08-28 23:04:28 +02:00
parent 629162d9db
commit dea95d4a43
2 changed files with 13 additions and 5 deletions

View File

@@ -1,11 +1,19 @@
use config::Config;
use serde::Deserialize;
use crate::models::WatcherConfig;
impl WatcherConfig {
#[derive(Debug, Deserialize, Clone)]
pub struct AppConfig {
pub watcher: WatcherConfig,
}
impl AppConfig {
pub fn from_env() -> Result<Self, config::ConfigError> {
// Load .env file (works in both Docker and local development)
dotenvy::dotenv().ok();
let cfg = config::Config::builder()
let cfg = Config::builder()
.add_source(config::Environment::with_prefix("WATCHER").separator("_"))
.build()?;

View File

@@ -7,7 +7,7 @@ pub mod hardware;
pub mod metrics;
pub mod models;
use models::WatcherConfig;
use crate::config::AppConfig;
use std::error::Error;
use std::marker::Send;
@@ -27,8 +27,8 @@ async fn flatten<T>(
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let config = WatcherConfig::from_env().expect("Failed to load configuration");
let server_url = config.server_url.clone();
let config = AppConfig::from_env().expect("Failed to load configuration");
let server_url = config.watcher.server_url.clone();
// Registration
let (server_id, ip) = match api::register_with_server(&server_url).await {