我有这个功能:
func functionX(collection []*interface{}) {
...
response, err := json.MarshalIndent(collection, "", " ")
...
}
Run Code Online (Sandbox Code Playgroud)
我希望collection参数允许任何类型的数组,这就是为什么我尝试使用*interface {}但我收到的错误是这样的:
cannot use MyDataType (type []*model.MyDataType) as type []*interface {} in argument to middleware.functionX
Run Code Online (Sandbox Code Playgroud)
你无法这样做,但是你可以轻松地做到这一点:
func functionX(collection interface{}) error {
...
response, err := json.MarshalIndent(collection, "", " ")
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
52 次 |
| 最近记录: |