Skip to content

Commit

Permalink
Support environment parameter configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmqtt committed Sep 13, 2023
1 parent 3b6c26d commit 23733a1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion rmqtt/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ impl Settings {
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));
.add_source(File::with_name("rmqtt").required(false))
.add_source(config::Environment::with_prefix("rmqtt"));

if let Some(cfg) = opts.cfg_name.as_ref() {
builder = builder.add_source(File::with_name(cfg).required(false));
Expand Down Expand Up @@ -242,7 +243,9 @@ impl Plugins {
let dir = self.dir.trim_end_matches(|c| c == '/' || c == '\\');
let s = Config::builder()
.add_source(File::with_name(&format!("{}/{}", dir, name)).required(required))
.add_source(config::Environment::with_prefix(&format!("rmqtt_plugin_{}", name.replace('-', "_"))))
.build()?;

let count = s.collect()?.len();
Ok((s.try_deserialize::<T>()?, count == 0))
}
Expand Down

0 comments on commit 23733a1

Please sign in to comment.