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

Function stringToWeakSliceHookFunc

viper.go:1005–1022  ·  view source on GitHub ↗

As of mapstructure v2.0.0 StringToSliceHookFunc checks if the return type is a string slice. This function removes that check. TODO: implement a function that checks if the value can be converted to the return type and use it instead.

(sep string)

Source from the content-addressed store, hash-verified

1003// This function removes that check.
1004// TODO: implement a function that checks if the value can be converted to the return type and use it instead.
1005func stringToWeakSliceHookFunc(sep string) mapstructure.DecodeHookFunc {
1006 return func(
1007 f reflect.Type,
1008 t reflect.Type,
1009 data interface{},
1010 ) (interface{}, error) {
1011 if f.Kind() != reflect.String || t.Kind() != reflect.Slice {
1012 return data, nil
1013 }
1014
1015 raw := data.(string)
1016 if raw == "" {
1017 return []string{}, nil
1018 }
1019
1020 return strings.Split(raw, sep), nil
1021 }
1022}
1023
1024// decode is a wrapper around mapstructure.Decode that mimics the WeakDecode functionality.
1025func decode(input any, config *mapstructure.DecoderConfig) error {

Callers 1

defaultDecoderConfigMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected