MCPcopy
hub / github.com/mitchellh/mapstructure / StringToSliceHookFunc

Function StringToSliceHookFunc

decode_hooks.go:104–120  ·  view source on GitHub ↗

StringToSliceHookFunc returns a DecodeHookFunc that converts string to []string by splitting on the given sep.

(sep string)

Source from the content-addressed store, hash-verified

102// StringToSliceHookFunc returns a DecodeHookFunc that converts
103// string to []string by splitting on the given sep.
104func 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.

Callers 1

Calls

no outgoing calls

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…