xxxxxxxxxx
package main
import (
"encoding/json"
"fmt"
)
func ToInterfaceSlice(v interface{}) []interface{} {
data := []interface{}{}
stringify, _ := json.Marshal(&v)
json.Unmarshal(stringify, &data)
return data
}
func main() {
b := []int{1, 2, 3, 4, 5}
sliceIFace := ToInterfaceSlice(b)
fmt.Println(sliceIFace)
}
xxxxxxxxxx
type Strings []string
func (ss Strings) ToInterfaceSlice() []interface{} {
iface := make([]interface{}, len(ss))
for i := range ss {
iface[i] = ss[i]
}
return iface
}