fix(config): unset CONFIG environment variable to avoid conflicts

This commit is contained in:
Orhun Parmaksız 2022-03-13 21:12:10 +03:00
parent e3a97045f4
commit 1dd5dcf167
No known key found for this signature in database
GPG key ID: F83424824B3E4B90
2 changed files with 13 additions and 4 deletions

View file

@ -9,7 +9,8 @@ use std::time::Duration;
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct Config {
/// Configuration settings.
pub config: Option<Settings>,
#[serde(rename = "config")]
pub settings: Option<Settings>,
/// Server configuration.
pub server: ServerConfig,
/// Paste configuration.

View file

@ -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)),