Closed mehdy closed 2 months ago
👋 Thanks for reporting!
A maintainer will take a look at your issue shortly. 👀
In the meantime: We are working on Viper v2 and we would love to hear your thoughts about what you like or don't like about Viper, so we can improve or fix those issues.
⏰ If you have a couple minutes, please take some time and share your thoughts: https://forms.gle/R6faU74qPRPAzchZ9
📣 If you've already given us your feedback, you can still help by spreading the news, either by sharing the above link or telling people about this on Twitter:
https://twitter.com/sagikazarmark/status/1306904078967074816
Thank you! ❤️
@mehdy I have the same issue as you. Your method seems similar to the one mentioned in https://github.com/spf13/viper/issues/584. Viper has implemented BindStruct
in https://github.com/spf13/viper/pull/1429 but didn't turn on for backward compatibility(https://github.com/spf13/viper/issues/1706). For your case, you can turn on viper_bind_struct
as the following command:
THAT=123 go run -tags viper_bind_struct test.go
That's weird and undocumented! But then it means I should close this issue.
Preflight Checklist
Problem Description
When you want to use environment variables as a source of configuration you need to bind each item explicitly or have another source of configuration to populate the store and then be able to use
AutomaticEnv
to override the values from the environment variables.So this piece of code is not doing what I'd expect:
P.S. This feels like an issue that should've been brought up many times but couldn't find another issue like this so I apologize in-advance if it's redundant.
Proposed Solution
To solve the issue I wrote this function and it could be a part of Viper itself.
So if Viper had a method like this it'd be so easy to tell it to bind all configurations defined by my Config struct.
If you're up for it I'd like to make a PR for it.
Alternatives Considered
No response
Additional Information
No response