Skip to content

Commit

Permalink
Make it easier to override config via env vars
Browse files Browse the repository at this point in the history
Although technically enabled, environment vars are rather useless at the
moment. Allow to override config values via specifying a distinct
prefix (to distinguish from underscore in the variable names), and
enable parsing for working types other than string.
  • Loading branch information
erthalion committed Nov 10, 2023
1 parent 73d8499 commit 606a01a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ fn main() {
.add_source(config::File::with_name("/etc/berserker/workload.toml").required(false))
.add_source(config::File::with_name("workload.toml").required(false))
// Add in settings from the environment (with a prefix of APP)
// Eg.. `WORKLOAD_DEBUG=1 ./target/app` would set the `debug` key
.add_source(config::Environment::with_prefix("WORKLOAD"))
// Eg.. `BERSERKER__WORKLOAD__ARRIVAL_RATE=1` would set the `arrival_rate` key
.add_source(config::Environment::with_prefix("BERSERKER").try_parsing(true).separator("__"))
.build()
.unwrap()
.try_deserialize::<WorkloadConfig>()
Expand Down

0 comments on commit 606a01a

Please sign in to comment.