我知道我可以用带有 的字符串填充 Go 切片strings := []string{"something", "something else"},但是除了接口之外,我怎么能做同样的事情呢?我尝试了以下方法:
data := []interface{}{{ID: "123"}, {ID: "456"}}
并得到以下错误:
missing type in composite literal
我也尝试过使用这样的结构:
type Users struct {
ID string
}
[]Users{{ID: "123"}, {ID: "456"}}
哪个有效,但是mongo的InsertMany函数需要一个[]interface{}参数:
cannot use users (type []Users) as type []interface {} in argument to database.InsertMany
如何定义和填充一个[]interface{}?
去
界面
片
慕妹3146593
米琪卡哇伊
杨魅力
随时随地看视频慕课网APP
相关分类