我有這個功能:func functionX(collection []*interface{}) { ... response, err := json.MarshalIndent(collection, "", " ") ...}我希望集合參數(shù)允許任何類型的數(shù)組,這就是為什么我嘗試使用*interface{}但我收到如下錯誤:cannot use MyDataType (type []*model.MyDataType) as type []*interface {} in argument to middleware.functionX
1 回答

九州編程
TA貢獻1785條經(jīng)驗 獲得超4個贊
你不能那樣做,但是你可以很容易地做到這一點:
func functionX(collection interface{}) error {
...
response, err := json.MarshalIndent(collection, "", " ")
...
}
- 1 回答
- 0 關(guān)注
- 172 瀏覽
添加回答
舉報
0/150
提交
取消