InterfaceSliceToStringSlice converts a slice of interfaces to a slice of strings
(input any)
| 348 | |
| 349 | // InterfaceSliceToStringSlice converts a slice of interfaces to a slice of strings |
| 350 | func InterfaceSliceToStringSlice(input any) ([]string, error) { |
| 351 | switch v := input.(type) { |
| 352 | case []any: |
| 353 | raw := make([]string, len(v)) |
| 354 | for i := range v { |
| 355 | if s, ok := v[i].(string); ok { |
| 356 | raw[i] = s |
| 357 | } else { |
| 358 | return nil, fmt.Errorf("%v is not a string", v[i]) |
| 359 | } |
| 360 | } |
| 361 | return raw, nil |
| 362 | default: |
| 363 | return nil, fmt.Errorf("unexpected type: %T", input) |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | // SliceToUniqueSlice processes a slice of string to make sure there are no duplicates |
| 368 | func SliceToUniqueSlice(inSlice *[]string) []string { |