-
Notifications
You must be signed in to change notification settings - Fork 31
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
Matching environment variables with snake_case and nested structs #12
Comments
Have you read the In your case, one quick-and-easy solution is to remove your use of env.map(|k| match k {
k if k == "node_identifier" => k.into(),
k => k.as_str().replace("_", ".").into()
}) |
Sure, I read the docs on nesting, with an emphasis on the mentioned Carefully registering each nesting and field by hand in the configuration loading code did not seem to be the way to go. I mean, it seemed to be a better choice to drop nesting as opposed to managing a complex configuration loading logic. Thus, I actually opened this issue aware of your proposed solution, but with the thought that '"there must be a cleaner way than this" 😄 |
Got it. The difficulty here is that there does not exist an unambiguous way to split an environment variable name into nestings. For example, the name This is why Figment supports the unambiguous
Nevertheless, for cases where an ambiguity does not exist, or a preference strategy is desired, we could imagine a |
Yeah, that's completely reasonable, thanks for the detailed explanation. Most probably, I got confused because the frameworks and libraries I worked with so far either required explicit environment variable names (such as node-convict) or inferred the environment variable names based on the target class/object/struct hierarchy (such as config or the Spring framework). Thanks again for the provided insights, I may revisit this issue going down the |
Hey,
first of all, many thanks for maintaining this library. It is truly of great help for developing configurable applications.
My issue is as follows. In my application I prefer to use nested structs for my configuration, for example:
Since I want stuff to be configurable via environment variables, I use
Env::prefixed
along withsplit
to handle nestings correctly. SoAPP_LOG_FORMAT
works.However, things start to get messy when I add snake_case fields to the mix:
In this case, Figment is unable to correctly resolve
APP_NODE_IDENTIFIER
as it assumes anode.identifier
nesting when employingsplit
. Thus, I have to choose between "nesting with no multi-word/snake_case field names" and "snake_case but no nesting".Is there any way to use environment variables, nested structs and snake_case field names at the same time, out-of-the-box?
Bests,
Attila
The text was updated successfully, but these errors were encountered: