Issue-105 Support time.Duration in viper.Unmarshal

This commit is contained in:
Yauhen Lazurkin 2016-07-09 15:37:52 +03:00
parent c1ccc378a0
commit e38b8a3bb3

View file

@ -611,7 +611,19 @@ func (v *Viper) UnmarshalKey(key string, rawVal interface{}) error {
// on the fields of the structure are properly set. // on the fields of the structure are properly set.
func Unmarshal(rawVal interface{}) error { return v.Unmarshal(rawVal) } func Unmarshal(rawVal interface{}) error { return v.Unmarshal(rawVal) }
func (v *Viper) Unmarshal(rawVal interface{}) error { func (v *Viper) Unmarshal(rawVal interface{}) error {
err := mapstructure.WeakDecode(v.AllSettings(), rawVal) config := &mapstructure.DecoderConfig{
Metadata: nil,
Result: rawVal,
WeaklyTypedInput: true,
DecodeHook: mapstructure.StringToTimeDurationHookFunc(),
}
decoder, err := mapstructure.NewDecoder(config)
if err != nil {
return err
}
err = decoder.Decode(v.AllSettings())
if err != nil { if err != nil {
return err return err