From 1dd5dcf1678463bf533fb34b7121711a346d476f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Sun, 13 Mar 2022 21:12:10 +0300 Subject: [PATCH] fix(config): unset `CONFIG` environment variable to avoid conflicts --- src/config.rs | 3 ++- src/main.rs | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/config.rs b/src/config.rs index 7c02da2..f8e70e4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,7 +9,8 @@ use std::time::Duration; #[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)] pub struct Config { /// Configuration settings. - pub config: Option, + #[serde(rename = "config")] + pub settings: Option, /// Server configuration. pub server: ServerConfig, /// Paste configuration. diff --git a/src/main.rs b/src/main.rs index 0929bd0..7042263 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,9 @@ use std::path::PathBuf; use std::sync::{Arc, RwLock}; use std::time::Duration; +/// Environment variable for setting the configuration file path. +const CONFIG_ENV: &str = "CONFIG"; + #[actix_web::main] async fn main() -> IoResult<()> { // Initialize logger. @@ -19,8 +22,13 @@ async fn main() -> IoResult<()> { // Parse configuration. dotenv::dotenv().ok(); - let config_path = - PathBuf::from(env::var("CONFIG").unwrap_or_else(|_| String::from("config.toml"))); + let config_path = match env::var(CONFIG_ENV).ok() { + Some(path) => { + env::remove_var(CONFIG_ENV); + PathBuf::from(path) + } + None => PathBuf::from("config.toml"), + }; let config = Config::parse(&config_path).expect("failed to parse config"); let server_config = config.server.clone(); @@ -33,7 +41,7 @@ async fn main() -> IoResult<()> { // Set up a watcher for the configuration file changes. let mut hotwatch = Hotwatch::new_with_custom_delay( config - .config + .settings .as_ref() .map(|v| v.refresh_rate) .unwrap_or_else(|| Duration::from_secs(1)),