mirror of
https://github.com/spf13/viper
synced 2024-12-23 12:07:02 +00:00
Added UnmarshalKeyExact() as well as non-method UnmarshalExact().
This commit is contained in:
parent
25b30aa063
commit
6d96b16143
1 changed files with 18 additions and 0 deletions
18
viper.go
18
viper.go
|
@ -768,6 +768,7 @@ func decode(input interface{}, config *mapstructure.DecoderConfig) error {
|
||||||
|
|
||||||
// UnmarshalExact unmarshals the config into a Struct, erroring if a field is nonexistent
|
// UnmarshalExact unmarshals the config into a Struct, erroring if a field is nonexistent
|
||||||
// in the destination struct.
|
// in the destination struct.
|
||||||
|
func UnmarshalExact(rawVal interface{}) error { return v.UnmarshalExact(rawVal) }
|
||||||
func (v *Viper) UnmarshalExact(rawVal interface{}) error {
|
func (v *Viper) UnmarshalExact(rawVal interface{}) error {
|
||||||
config := defaultDecoderConfig(rawVal)
|
config := defaultDecoderConfig(rawVal)
|
||||||
config.ErrorUnused = true
|
config.ErrorUnused = true
|
||||||
|
@ -782,6 +783,23 @@ func (v *Viper) UnmarshalExact(rawVal interface{}) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
// UnmarshalKeyExact takes a single key and unmarshals it into a Struct, erroring if a field
|
||||||
|
// is nonexistent in the destination struct.
|
||||||
|
func UnmarshalKeyExact(key string, rawVal interface{}) error { return v.UnmarshalKeyExact(key, rawVal) }
|
||||||
|
func (v *Viper) UnmarshalKeyExact(key string, rawVal interface{}) error {
|
||||||
|
config := defaultDecoderConfig(rawVal)
|
||||||
|
config.ErrorUnused = true
|
||||||
|
|
||||||
|
err := decode(v.Get(key), config)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
v.insensitiviseMaps()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// BindPFlags binds a full flag set to the configuration, using each flag's long
|
// BindPFlags binds a full flag set to the configuration, using each flag's long
|
||||||
// name as the config key.
|
// name as the config key.
|
||||||
|
|
Loading…
Reference in a new issue