我正在我的围棋项目中使用https://github.com/julienschmidt/httprouter。
不久前,我问了这个问题,@icza:httprouter configuring NotFound解决了这个问题,但现在,启动了一个新项目,并使用了非常类似的代码,我似乎在控制台中出现了错误。
尝试配置我正在使用的自定义处理程序NotFound和MethodNotAllowed:
router.NotFound = customNotFound
router.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
}在过去的几个月里,这个包是否发生了一些重大的变化,因为我不知道为什么我会在一个项目中得到错误,而不是在另一个项目中?
发布于 2015-08-26 11:24:25
由于提交70708e4600,所以router.NotFound不再是一个http.HandlerFunc,而是一个http.Handler。因此,如果您使用最近提交的httprouter,您将不得不通过http://golang.org/pkg/net/http/#HandlerFunc来调整您的函数。
下列措施应有效(未经测试):
router.NotFound = http.HandlerFunc(customNotFound)https://stackoverflow.com/questions/32224003
复制相似问题