added .env readability
This commit is contained in:
22
WatcherAgent/src/config.rs
Normal file
22
WatcherAgent/src/config.rs
Normal 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()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user