From 266e588e9eca7ee317e9f0446a01934675a4d261 Mon Sep 17 00:00:00 2001 From: Alexander Krasnukhin Date: Fri, 3 Mar 2017 12:09:20 +0100 Subject: [PATCH] Add string slice support to defaultDecoderConfig This way it correctly decodes string slices as well. --- viper.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/viper.go b/viper.go index 2a221e5..92366d6 100644 --- a/viper.go +++ b/viper.go @@ -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(","), + ), } }