ToStringSliceE casts any value to a []string type.
(i any)
| 80 | |
| 81 | // ToStringSliceE casts any value to a []string type. |
| 82 | func 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 | } |
no test coverage detected
searching dependent graphs…