Add string slice support to defaultDecoderConfig

This way it correctly decodes string slices as well.
This commit is contained in:
Alexander Krasnukhin 2017-03-03 12:09:20 +01:00 committed by Bjørn Erik Pedersen
parent 25b30aa063
commit 266e588e9e
1 changed files with 5 additions and 2 deletions

View File

@ -747,13 +747,16 @@ func (v *Viper) Unmarshal(rawVal interface{}) error {
}
// defaultDecoderConfig returns default mapsstructure.DecoderConfig with suppot
// of time.Duration values
// of time.Duration values & string slices
func defaultDecoderConfig(output interface{}) *mapstructure.DecoderConfig {
return &mapstructure.DecoderConfig{
Metadata: nil,
Result: output,
WeaklyTypedInput: true,
DecodeHook: mapstructure.StringToTimeDurationHookFunc(),
DecodeHook: mapstructure.ComposeDecodeHookFunc(
mapstructure.StringToTimeDurationHookFunc(),
mapstructure.StringToSliceHookFunc(","),
),
}
}