defaultDecoderConfig returns default mapstructure.DecoderConfig with support of time.Duration values & string slices.
(output any, opts ...DecoderConfigOption)
| 974 | // defaultDecoderConfig returns default mapstructure.DecoderConfig with support |
| 975 | // of time.Duration values & string slices. |
| 976 | func (v *Viper) defaultDecoderConfig(output any, opts ...DecoderConfigOption) *mapstructure.DecoderConfig { |
| 977 | decodeHook := v.decodeHook |
| 978 | if decodeHook == nil { |
| 979 | decodeHook = mapstructure.ComposeDecodeHookFunc( |
| 980 | mapstructure.StringToTimeDurationHookFunc(), |
| 981 | // mapstructure.StringToSliceHookFunc(","), |
| 982 | stringToWeakSliceHookFunc(","), |
| 983 | ) |
| 984 | } |
| 985 | |
| 986 | c := &mapstructure.DecoderConfig{ |
| 987 | Metadata: nil, |
| 988 | WeaklyTypedInput: true, |
| 989 | DecodeHook: decodeHook, |
| 990 | } |
| 991 | |
| 992 | for _, opt := range opts { |
| 993 | opt(c) |
| 994 | } |
| 995 | |
| 996 | // Do not allow overwriting the output |
| 997 | c.Result = output |
| 998 | |
| 999 | return c |
| 1000 | } |
| 1001 | |
| 1002 | // As of mapstructure v2.0.0 StringToSliceHookFunc checks if the return type is a string slice. |
| 1003 | // This function removes that check. |
no test coverage detected