Skip to content

Commit

Permalink
Explain how to set configuration values via env variables. (LukeMathW…
Browse files Browse the repository at this point in the history
…alker#207)

In particular, allow setting single fields of a nested configuration
struct using `split`.
  • Loading branch information
LukeMathWalker authored Feb 26, 2024
1 parent 6bdad64 commit 12c2ca9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/starter/server/src/configuration/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Config {
let figment = Figment::new()
.merge(Yaml::file(base_filepath))
.merge(Yaml::file(profile_filepath))
.merge(Env::prefixed("APP_"));
.merge(Env::prefixed("APP_").split("__"));

let configuration: Config = figment
.extract()
Expand Down
6 changes: 5 additions & 1 deletion libs/pavexc_cli/template/.env
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
APP_PROFILE=dev
APP_PROFILE=dev
# All env variables must be prefixed with `APP_` to be picked up at runtime.
# To set a nested field you need to use `__` as separator.
# For example, to set `Config.server.port` via an env variable
# it'd have to be named `APP_SERVER__PORT`.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Config {
let figment = Figment::new()
.merge(Yaml::file(base_filepath))
.merge(Yaml::file(profile_filepath))
.merge(Env::prefixed("APP_"));
.merge(Env::prefixed("APP_").split("__"));

let configuration: Config = figment
.extract()
Expand Down

0 comments on commit 12c2ca9

Please sign in to comment.