所以,我有这样的功能
func ProcessRequest(requestBody *SignInRequest, response func(SignInResponse) *src.Response, error func(ControllerError) *src.Response) *src.Response {
return error(ControllerError{Code: http.StatusNotImplemented})
}
而我试图称之为
ProcessRequest(payload, myFunction, handler.OnControllerError)
func myFunction(i interface{}) *src.Response {
}
这向我显示了一个错误
不能使用 'myFunction' (type func(i interface{}) *src.Response) 作为类型 func(SignInResponse) *src.Response
但是如果我尝试同样的事情
type TestStruct struct {
}
func myFunction2(i interface{}) *src.Response {
}
myFunction2(TestStruct{})
然后它没有显示任何错误。
我希望它interface{}作为一个论点,因为我想myFucntion成为可以接受任何struct.
饮歌长啸