-
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
feat: being able to add env name for a specific field #32
Comments
If you think that’s ok, I can work on it. |
Hi @mojixcoder, when loading from the environment using fig, it's important to consider the hierarchical nature of structs, especially when dealing with nested structs. Consider the following example: type Config struct {
Inner struct {
Field int `fig:"field"`
} `fig:"inner"`
} In this scenario, fig would search for an environment variable named INNER_FIELD to populate the Field within the Inner struct, assuming no specific prefix has been set. Coming back to your use case, are you looking to override the entire composite key derived from the nested structure, or are you only interested in modifying the key at the specific level of the nested field? |
The problem is that usually keys in type Config struct {
Jeager struct {
ServiceName string `fig:"serviceName" env:"JAEGER_SERVICE_NAME"`
} `fig:"jaeger"`
} If I want to load this variable using fig, It should be |
I'm hesitant on adding a new struct tag, as it increases cognitive complexity and introduces potential confusion regarding the precedence of various struct tags. An alternative could involve specifying an environment key creation strategy that This approach maintains simplicity for fig users and adds flexibility in how environment variable names are constructed. What do you think? |
This approach looks good to me. |
You should iterate and only split when an uppercase letter is preceded by a lowercase letter, so in your example |
Hello and thanks for your great package.
I have a specific use case in which env var is using another names which is different with the name generated by the
fig
for that field.Can we add a new feature to achieve this.
Something like this:
This way, the config is loaded from a file using the current approach. But if the
DIFFERENT_KEY
env is set, its value will be used for this field.The text was updated successfully, but these errors were encountered: