MCPcopy
hub / github.com/spf13/cast / ToStringSliceE

Function ToStringSliceE

slice.go:82–106  ·  view source on GitHub ↗

ToStringSliceE casts any value to a []string type.

(i any)

Source from the content-addressed store, hash-verified

80
81// ToStringSliceE casts any value to a []string type.
82func ToStringSliceE(i any) ([]string, error) {
83 if a, ok, err := toSliceEOk[string](i); ok {
84 if err != nil {
85 return nil, err
86 }
87
88 return a, nil
89 }
90
91 var a []string
92
93 switch v := i.(type) {
94 case string:
95 return strings.Fields(v), nil
96 case any:
97 str, err := ToStringE(v)
98 if err != nil {
99 return nil, fmt.Errorf(errorMsg, i, i, a)
100 }
101
102 return []string{str}, nil
103 default:
104 return nil, fmt.Errorf(errorMsg, i, i, a)
105 }
106}

Callers 2

ToStringSliceFunction · 0.85
ToStringMapStringSliceEFunction · 0.85

Calls 1

ToStringEFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…