We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I try to use unmarshal to struct and It's work great.
And now, I want to unmarshal yaml file to embedded struct. See example.
main.go
type Base struct { Foo string } type SomeStruct struct { Base } func ReturnToStruct(fileName string, dir string) SomeStruct { viper.SetConfigFile(fileName) viper.AddConfigPath(dir) if err := viper.ReadInConfig(); err != nil { xlog.Fatalf("fatal error config file: %s \n", err) } someStruct := SomeStruct{} if err := viper.Unmarshal(&someStruct); err != nil { xlog.Fatalf("%v", err) } return someStruct }
test.yml
Foo: asd
When I use
xlog.Infof("%s", someStruct.Foo)
It will return empty string.
Can I use viper with embedded struct ?
The text was updated successfully, but these errors were encountered:
Viper actually uses mapstructure.
Try mapstructure:",squash" struct tag on the embedded struct.
mapstructure:",squash"
Sorry, something went wrong.
@sagikazarmark It work like a charm. Thanks you.
Why should I add a tag ? Can Viper set this feature as default ? Default to support emebeded field is a good idea!!!!
No branches or pull requests
I try to use unmarshal to struct and It's work great.
And now, I want to unmarshal yaml file to embedded struct. See example.
main.go
test.yml
When I use
It will return empty string.
Can I use viper with embedded struct ?
The text was updated successfully, but these errors were encountered: