added .env readability

This commit is contained in:
2025-08-11 21:33:19 +02:00
parent df36cb53c7
commit 9e851c310c
5 changed files with 40 additions and 20 deletions

View File

@@ -0,0 +1,22 @@
use config::Config;
use serde::Deserialize;
use crate::models::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 mut cfg = config::Config::builder()
.add_source(config::Environment::with_prefix("WATCHER").separator("_"))
.build()?;
cfg.try_deserialize()
}
}