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)
| 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. |
| 1005 | func 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. |
| 1025 | func decode(input any, config *mapstructure.DecoderConfig) error { |
no outgoing calls
no test coverage detected