Skip to content

Commit

Permalink
Upgrade deps to config = "0.13"
Browse files Browse the repository at this point in the history
  • Loading branch information
rmqtt committed Sep 12, 2023
1 parent 922da0b commit 3b6c26d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion rmqtt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ uuid = { version = "1.1", features = ["v4"] }
rand = "0.8"
crossbeam = "0.8"
governor = "0.6"
config = { version = "0.11", default-features = false, features = ["toml"] }
config = { version = "0.13", default-features = false, features = ["toml"] }
log = { version = "0.4", features = ["std"] }
slog = "2.7"
slog-term = "2.9"
Expand Down
26 changes: 12 additions & 14 deletions rmqtt/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,16 @@ impl Deref for Settings {

impl Settings {
fn new(opts: Options) -> Result<Self> {
let mut s = Config::new();

// if let Ok(cfg_filename) = std::env::var("RMQTT-CONFIG-FILENAME") {
// s.merge(File::with_name(&cfg_filename).required(false))?;
// }
s.merge(File::with_name("/etc/rmqtt/rmqtt").required(false))?;
s.merge(File::with_name("/etc/rmqtt").required(false))?;
s.merge(File::with_name("rmqtt").required(false))?;
let mut builder = Config::builder()
.add_source(File::with_name("/etc/rmqtt/rmqtt").required(false))
.add_source(File::with_name("/etc/rmqtt").required(false))
.add_source(File::with_name("rmqtt").required(false));

if let Some(cfg) = opts.cfg_name.as_ref() {
s.merge(File::with_name(cfg).required(false))?;
builder = builder.add_source(File::with_name(cfg).required(false));
}

let mut inner: Inner = s.try_into()?;
let mut inner: Inner = builder.build()?.try_deserialize()?;

inner.listeners.init();
if inner.listeners.tcps.is_empty() && inner.listeners.tlss.is_empty() {
Expand Down Expand Up @@ -243,10 +240,11 @@ impl Plugins {
required: bool,
) -> Result<(T, bool)> {
let dir = self.dir.trim_end_matches(|c| c == '/' || c == '\\');
let mut s = Config::new();
s.merge(File::with_name(&format!("{}/{}", dir, name)).required(required))?;
let s = Config::builder()
.add_source(File::with_name(&format!("{}/{}", dir, name)).required(required))
.build()?;
let count = s.collect()?.len();
Ok((s.try_into::<T>()?, count == 0))
Ok((s.try_deserialize::<T>()?, count == 0))
}
}

Expand Down Expand Up @@ -524,7 +522,7 @@ impl<'de> de::Deserialize<'de> for NodeAddr {
#[inline]
fn timestamp_parse_from_str(ts: &str, fmt: &str) -> anyhow::Result<i64> {
let ndt = chrono::NaiveDateTime::parse_from_str(ts, fmt)?;
let ndt = ndt.and_local_timezone(chrono::Local::now().offset().clone());
let ndt = ndt.and_local_timezone(*chrono::Local::now().offset());
match ndt {
LocalResult::None => Err(anyhow::Error::msg("Impossible")),
LocalResult::Single(d) => Ok(d.timestamp()),
Expand Down

0 comments on commit 3b6c26d

Please sign in to comment.