ToArrayStr converts an empty interface type to a slice of strings. If any element in the array cannot be converted, then nil is returned along with a second value of false. If the input data could be entirely converted, then the converted data, along with a second value of true, will be returned.
(data interface{})
| 162 | // converted, then the converted data, along with a second value of true, |
| 163 | // will be returned. |
| 164 | func toArrayStr(data interface{}) ([]string, bool) { |
| 165 | // Is there a better way to do this with reflect? |
| 166 | if d, ok := data.([]interface{}); ok { |
| 167 | result := make([]string, len(d)) |
| 168 | for i, el := range d { |
| 169 | item, ok := el.(string) |
| 170 | if !ok { |
| 171 | return nil, false |
| 172 | } |
| 173 | result[i] = item |
| 174 | } |
| 175 | return result, true |
| 176 | } |
| 177 | return nil, false |
| 178 | } |
| 179 | |
| 180 | func isSliceType(v interface{}) bool { |
| 181 | if v == nil { |