From bf529a901bd8b02e76c359470b3c98cab286f883 Mon Sep 17 00:00:00 2001 From: Daniel Sockwell Date: Tue, 7 Jan 2020 13:07:54 -0500 Subject: [PATCH] Treat env vars set to "" as if they were unset (#73) * Treat env vars set to "" as if they were unset * Bump version to 0.4.4 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/config/mod.rs | 18 +++++++++++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 19cf9ac..75c52fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -404,7 +404,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "flodgatt" -version = "0.4.3" +version = "0.4.4" dependencies = [ "criterion 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "dotenv 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 20132f5..229da5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "flodgatt" description = "A blazingly fast drop-in replacement for the Mastodon streaming api server" -version = "0.4.3" +version = "0.4.4" authors = ["Daniel Long Sockwell "] edition = "2018" diff --git a/src/config/mod.rs b/src/config/mod.rs index 01dd633..b2b314d 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -117,13 +117,21 @@ macro_rules! from_env_var { $body } pub fn maybe_update(self, var: Option<&String>) -> Self { - if let Some(value) = var { - Self(Self::inner_from_str(value).unwrap_or_else(|| { + match var { + Some(empty_string) if empty_string.is_empty() => Self::default(), + Some(value) => Self(Self::inner_from_str(value).unwrap_or_else(|| { crate::err::env_var_fatal($env_var, value, $allowed_values) - })) - } else { - self + })), + None => self, } + + // if let Some(value) = var { + // Self(Self::inner_from_str(value).unwrap_or_else(|| { + // crate::err::env_var_fatal($env_var, value, $allowed_values) + // })) + // } else { + // self + // } } } };