Closed bentcoder closed 5 years ago
Sure that should work somehow. Just stick to one type (http.Handler, http.HandlerFunc or httprouter.Handle) consistently:
func Admin(rw http.ResponseWriter, rq *http.Request) {
fmt.Println("Welcome admin")
}
func Middleware1(h http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
h(w, r)
}
}
func Middleware2(h http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
h(w, r)
}
}
rtr.HandlerFunc("POST", "/admin", Middleware2(Middleware1(Admin)))
Or am I not understanding your question correctly?
You got it right, thank you!
Hi,
Apologies in advance as this is my issue not the package's issue.
I am looking for a way to use chain of middleware for routes(endpoints) I have but couldn't find an example. Is what I am trying to do below possible?
NOTE: I want to stick with
(rw http.ResponseWriter, rq *http.Request)
signature withoutparams
though. Otherwise it is very easy to create middleware.Thanks
These tries ones didn't work - I know some of them are irrelevant but just trying to explain what I mean if my explanation above wasn't clear enough.