我可以将结构切片指针作为接口切片指针传递吗?
https://play.golang.org/p/EyhGYknZvT2
func (r *Randomizer) ShuffleAry(ary *[]interface{}) (v []interface{}) {
r.mu.Lock()
tmp := make([]int, len(*ary))
v = make([]interface{}, len(*ary))
for index := range tmp {
tmp[index] = index
}
// v = append(v, *ary...)
r.rand.Shuffle(len(tmp), func(i, j int) { tmp[i], tmp[j] = tmp[j], tmp[i] })
for index, newIndex := range tmp {
v[index] = (*ary)[newIndex]
}
r.mu.Unlock()
return
}
收到cannot use &txx (type *[]Tx) as type *[]interface {} in argument to r.ShuffleAry错误消息
人到中年有点甜
相关分类