I'm struggling to get my route specific middleware working with httprouter and Negroni. The login route requires Middleware2
and all the other routes require Middleware1
.
So far I have:
func Main() {
router := httprouter.New()
protectedRoutes := httprouter.New()
DefineRoutes(router)
DefineProtectedRoutes(protectedRoutes)
//This is the block that I'm unsure about
//How can I introduce Middleware2 for a specific route?
n := negroni.New()
n.Use(negroni.HandlerFunc(Middleware1))
n.UseHandler(router)
n.Run(":5000")
}
func DefineRoutes(router *httprouter.Router) {
router.POST("/v1/users/authenticate", UserLogin)
router.POST("/v1/users/authorize", UserLogin)
router.POST("/v1/users/logout", UserLogout)
}
func DefineProtectedRoutes(router *httprouter.Router) {
router.POST("/v1/users/login", UserLogin)
}
but now I'm a bit stuck as the examples on the site (https://github.com/codegangsta/negroni) use the standard handlers.
httprouter.Params
– Not_a_Golfer