Gorilla Mux router from inside handler only works once then gives 404 page not found

北城以北 提交于 2019-12-01 12:48:52

The problem is Subrouter() isn't made to return the router, but to create one, thus it changes the matcher of the router it is called on, making you lose the handler.

You could try passing the router to the handler using closures instead.

func RootHandler(router *mux.Router) func(http.ResponseWriter, *http.Request) {
    return func(w http.ResponseWriter, r *http.Request) {
        ...
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!