blob: 1321ba1c9be633c28abbb50510fdc2803752fe8a [file] [log] [blame]
package mapstructure
import (
"reflect"
"strings"
)
// StringToSliceHookFunc returns a DecodeHookFunc that converts
// string to []string by splitting on the given sep.
func StringToSliceHookFunc(sep string) DecodeHookFunc {
return func(
f reflect.Kind,
t reflect.Kind,
data interface{}) (interface{}, error) {
if f != reflect.String || t != reflect.Slice {
return data, nil
}
raw := data.(string)
return strings.Split(raw, sep), nil
}
}