nostr-rs-relay

My dev fork of nostr-rs-relay
git clone git://jb55.com/nostr-rs-relay
Log | Files | Refs | README | LICENSE

commit 414e83f696e5b25b58400ed8169ca38d99f1302f
parent 225c8f762eb4939274e17dc4ae245f9266ef0f67
Author: Greg Heartsfield <scsibug@imap.cc>
Date:   Sat, 26 Feb 2022 11:06:23 -0600

refactor: import cleanup for config

Diffstat:
Msrc/config.rs | 19+++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/config.rs b/src/config.rs @@ -1,4 +1,5 @@ //! Configuration file and settings management +use config::{Config, ConfigError, File}; use lazy_static::lazy_static; use log::*; use serde::{Deserialize, Serialize}; @@ -138,27 +139,25 @@ pub struct Settings { impl Settings { pub fn new() -> Self { - let d = Self::default(); + let default_settings = Self::default(); // attempt to construct settings with file - // Self::new_from_default(&d).unwrap_or(d) - let from_file = Self::new_from_default(&d); + let from_file = Self::new_from_default(&default_settings); match from_file { Ok(f) => f, Err(e) => { warn!("Error reading config file ({:?})", e); - d + default_settings } } } - fn new_from_default(default: &Settings) -> Result<Self, config::ConfigError> { - // let config: config::Config = config::Config::new(); - let builder = config::Config::builder(); - let config: config::Config = builder + fn new_from_default(default: &Settings) -> Result<Self, ConfigError> { + let builder = Config::builder(); + let config: Config = builder // use defaults - .add_source(config::Config::try_from(default)?) + .add_source(Config::try_from(default)?) // override with file contents - .add_source(config::File::with_name("config")) + .add_source(File::with_name("config")) .build()? .try_into() .unwrap();