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

View file

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