ToUniqueStringSlice casts `value` to a slice of non-zero unique strings.
(value any)
| 109 | |
| 110 | // ToUniqueStringSlice casts `value` to a slice of non-zero unique strings. |
| 111 | func ToUniqueStringSlice(value any) (result []string) { |
| 112 | switch val := value.(type) { |
| 113 | case nil: |
| 114 | // nothing to cast |
| 115 | case []string: |
| 116 | result = val |
| 117 | case string: |
| 118 | if val == "" { |
| 119 | break |
| 120 | } |
| 121 | |
| 122 | // check if it is a json encoded array of strings |
| 123 | if strings.Contains(val, "[") { |
| 124 | if err := json.Unmarshal([]byte(val), &result); err != nil { |
| 125 | // not a json array, just add the string as single array element |
| 126 | result = append(result, val) |
| 127 | } |
| 128 | } else { |
| 129 | // just add the string as single array element |
| 130 | result = append(result, val) |
| 131 | } |
| 132 | case json.Marshaler: // eg. JSONArray |
| 133 | raw, _ := val.MarshalJSON() |
| 134 | _ = json.Unmarshal(raw, &result) |
| 135 | default: |
| 136 | result = cast.ToStringSlice(value) |
| 137 | } |
| 138 | |
| 139 | return NonzeroUniques(result) |
| 140 | } |
| 141 | |
| 142 | // ToChunks splits list into chunks. |
| 143 | // |
searching dependent graphs…