MCPcopy
hub / github.com/spf13/viper / defaultDecoderConfig

Method defaultDecoderConfig

viper.go:976–1000  ·  view source on GitHub ↗

defaultDecoderConfig returns default mapstructure.DecoderConfig with support of time.Duration values & string slices.

(output any, opts ...DecoderConfigOption)

Source from the content-addressed store, hash-verified

974// defaultDecoderConfig returns default mapstructure.DecoderConfig with support
975// of time.Duration values & string slices.
976func (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.

Callers 4

UnmarshalKeyMethod · 0.95
UnmarshalMethod · 0.95
decodeStructKeysMethod · 0.95
UnmarshalExactMethod · 0.95

Calls 1

Tested by

no test coverage detected