将DBDiskGroupInfo 转换为DiskGroupInfo
还有跟快的吗???
~~~
package main
import (
"fmt"
"unsafe"
)
type DBDiskGroupInfo struct {
ZoneID int32 `bson:"ZoneID"`
GroupID int32 `bson:"GroupID"`
Status int32 `bson:"Status"`
Dids []int32 `bson:"DidList"`
}
type DiskGroupInfo struct {
ZoneID uint32 `bson:"ZoneID"`
GroupID uint32 `bson:"GroupID"`
Status uint32 `bson:"Status"`
Dids []uint32 `bson:"DidList"`
}
func (x *DBDiskGroupInfo) test3() (tmp DiskGroupInfo) {
tmp.ZoneID = uint32(x.ZoneID)
tmp.GroupID = uint32(x.GroupID)
tmp.Status = uint32(x.Status)
y := (*[]uint32)(unsafe.Pointer(&x.Dids))
tmp.Dids = make([]uint32, len(x.Dids))
copy(tmp.Dids, *y)
return tmp
}
func main() {
var x DBDiskGroupInfo
x.ZoneID = 1
x.GroupID = 2
x.Status = 3
x.Dids = make([]int32, 0)
x.Dids = append(x.Dids, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 3, 4)
y := x.test3()
fmt.Println(y)
}
~~~
有疑问加站长微信联系(非本文作者)