toSlice returns the reflect.Value of v, turning it into a single element slice (of type sliceTy) if it isn't a slice already.
(v interface{}, sliceTy reflect.Type)
| 175 | // toSlice returns the reflect.Value of v, turning it into a single element |
| 176 | // slice (of type sliceTy) if it isn't a slice already. |
| 177 | func toSlice(v interface{}, sliceTy reflect.Type) reflect.Value { |
| 178 | e := reflect.ValueOf(v) |
| 179 | if e.Kind() == reflect.Slice { |
| 180 | return e |
| 181 | } |
| 182 | s := reflect.MakeSlice(sliceTy, 1, 1) |
| 183 | s.Index(0).Set(e) |
| 184 | return s |
| 185 | } |