func Test_toInt64Slice(t *testing.T) {
res, err := toInt64Slice([]int64{1})
fmt.Println(err, res)
}
func toInt64Slice(actual interface{}) ([]int64, error) {
var res []int64
value := reflect.ValueOf(actual)
if value.Kind() != reflect.Slice && value.Kind() != reflect.Array {
return nil, errors.New("parse error")
}
for i := 0; i < value.Len(); i++ {
res = append(res, value.Index(i).Interface().(int64))
}
return res ,nil
}
go interface{}类型转换为数组或者切片
最新推荐文章于 2023-12-23 22:56:04 发布