我在 Go 项目中使用https://github.com/julienschmidt/httprouter。不久前我问了这个问题,@ icza解决了这个问题:httprouter 配置 NotFound但现在,开始一个新项目并使用非常相似的代码,我似乎在控制台中遇到错误。尝试配置自定义处理程序NotFound,MethodNotAllowed我正在使用:router.NotFound = customNotFoundrouter.MethodNotAllowed = customMethodNotAllowed产生:cannot use customNotFound (type func(http.ResponseWriter, *http.Request)) as type http.Handler in assignment: func(http.ResponseWriter, *http.Request) does not implement http.Handler (missing ServeHTTP method) cannot use customMethodNotAllowed (type func(http.ResponseWriter, *http.Request)) as type http.Handler in assignment: func(http.ResponseWriter, *http.Request) does not implement http.Handler (missing ServeHTTP method) 我的功能如下所示:func customNotFound(w http.ResponseWriter, r *http.Request) { core.WriteError(w, "PAGE_NOT_FOUND", "Requested resource could not be found") return}func customMethodNotAllowed(w http.ResponseWriter, r *http.Request) { core.WriteError(w, "METHOD_NOT_PERMITTED", "Request method not supported by that resource") return}在过去的几个月里,这个包是否发生了一些重大变化,因为我不知道为什么我在一个项目中而不是在另一个项目中收到错误?
1 回答
- 1 回答
- 0 关注
- 187 浏览
添加回答
举报
0/150
提交
取消