StringToSliceHookFunc returns a DecodeHookFunc that converts string to []string by splitting on the given sep.
(sep string)
| 102 | // StringToSliceHookFunc returns a DecodeHookFunc that converts |
| 103 | // string to []string by splitting on the given sep. |
| 104 | func StringToSliceHookFunc(sep string) DecodeHookFunc { |
| 105 | return func( |
| 106 | f reflect.Kind, |
| 107 | t reflect.Kind, |
| 108 | data interface{}) (interface{}, error) { |
| 109 | if f != reflect.String || t != reflect.Slice { |
| 110 | return data, nil |
| 111 | } |
| 112 | |
| 113 | raw := data.(string) |
| 114 | if raw == "" { |
| 115 | return []string{}, nil |
| 116 | } |
| 117 | |
| 118 | return strings.Split(raw, sep), nil |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // StringToTimeDurationHookFunc returns a DecodeHookFunc that converts |
| 123 | // strings to time.Duration. |
no outgoing calls
searching dependent graphs…