parseCommaSeparatedOrNewlineList splits a string by commas and/or newlines, trims surrounding whitespace from each item, and discards empty items.
(s string)
| 64 | // parseCommaSeparatedOrNewlineList splits a string by commas and/or newlines, |
| 65 | // trims surrounding whitespace from each item, and discards empty items. |
| 66 | func parseCommaSeparatedOrNewlineList(s string) []string { |
| 67 | // Normalize newlines to commas, then split on comma. |
| 68 | normalized := strings.ReplaceAll(s, "\n", ",") |
| 69 | parts := strings.Split(normalized, ",") |
| 70 | result := make([]string, 0, len(parts)) |
| 71 | for _, p := range parts { |
| 72 | p = strings.TrimSpace(p) |
| 73 | if p != "" { |
| 74 | result = append(result, p) |
| 75 | } |
| 76 | } |
| 77 | return result |
| 78 | } |
| 79 | |
| 80 | // toAnySlice converts a []string to []any for storage in a map[string]any. |
| 81 | func toAnySlice(ss []string) []any { |