-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Viper does not unmarshal values passed from env or pflag #1365
Comments
👋 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, https://twitter.com/sagikazarmark/status/1306904078967074816 Thank you! ❤️ |
@pantelis-karamolegkos I think I hit the same bug. |
I also encountered this issue, and there are several more open issues related to this.
This can be made more explicit if the // pass this function to the viper.Unmarshal() call
func DecoderErrorUnset(c *mapstructure.DecoderConfig) {
c.ErrorUnset = true
}
func InitConfig(cmd *cobra.Command) {
var conf Config
v := viper.New()
// ... other setup, see original post
v.Unmarshal(&conf, DecoderErrorUnset)
} In my opinion when unmarshaling into well defined structs, the struct should be introspected, and then viper should be queried if it knows about the configuration options. Currently it is the other way around - if viper doesn't know about a field in the first place, it will be simply ignored during unmarshaling. |
Preflight Checklist
Viper Version
1.11.0
Go Version
1.17
Config Source
Flags, Environment variables
Format
No response
Repl.it link
No response
Code reproducing the issue
Expected Behavior
after
or either running as
the program should be printing
Actual Behavior
the program just prints
Steps To Reproduce
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: