-
Notifications
You must be signed in to change notification settings - Fork 235
Set hierarchical child config via env #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I was looking for this myself and looked in the code for it. There's a https://github.com/mehcode/config-rs/blob/master/src/env.rs#L108 |
Ah okay that's nice! I guess then it would make sense to have a separator different than |
This makes it impossible to use variables with underscore, which is a bit of a standard in Rust. The alternative would be to use single underscore for prefix and double underscore for nested config, which is not very readable. It still seems the best solution to read envs manually for any nested config. |
Config 0.9 removes this behavior by default. See the |
Which behaviour are you referring to? I meant that it's not possible to have config variables with underscore in the name, because they will be perceived as nested if an underscore separator is used. For example using something like this:
with will create a key Maybe it's not a good idea using underscores in variable names in this case. |
That's the exact behavior. I meant that that the // SETTINGS_BRAINTREE__PUBLIC_KEY
// braintree.public_key
Environment::with_prefix("SETTINGS").separator("__") The |
On another note, in v0.10, this will likely change to: env::vars().prefix("settings_").map(|s| s.replace("__", "."))
See #111 for more details |
Thanks for the reply! I've decided to stick with reading all nested envs manually instead of the double underscore as I don't like the readability. I honestly don't see any other way around this though. |
For something like in the hierarchicalenv example:
Is it possible to set Braintree.public_key via an env or do I have to separately parse env for each child struct and then merge?
The text was updated successfully, but these errors were encountered: