Closed tcurdt closed 9 years ago
Your interceptor is calling mux.Vars
before it calls the router, so the router code which extracts the route vars hasn't run yet.
Ahhhhhhhh!
Not sure there is a suggested way of handling such things but simple chaining did the trick for me:
router.HandleFunc("/feedback/{project:[0-9a-zA-Z]+}", handler.Test(handler.PutProject)).Methods("PUT")
And then I can either call the callback to pass it on in the chain or handle it myself
func Test(router http.HandlerFunc) http.HandlerFunc {
return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
glog.Infof("Vars: [%q]", vars)
router(res, req)
})
}
I bet it's just me doing something wrong - but then I would ask to improve the docs. Here is what I am trying:
With the interceptors along the lines of:
and
Pretty straight forward. But somehow the variables are empty inside the interceptor.
As you can see from the logs the request does get matched correctly and the request uri looks OK - but there is no var "project".
What am I missing here?