'Bind mutiple routers - Golang Gorilla Mux
I have the following grouped routes, that use different middlewares
func userRoutes(handlers *Handler) *mux.Router {
router := mux.NewRouter()
// Routes here
router.HandleFunc("/accounts", handlers.ListAccounts).Name("list-account")
router.HandleFunc("/accounts/{id}", handlers.SingleAccount).Name("single-account")
// Middleware registration
router.Use(
middleware.Logger,)
return router
}
func staffRoutes(handlers *Handler) *mux.Router {
router := mux.NewRouter()
// Routes here
// Middleware registration
router.Use()
return router
}
func adminRoutes(handlers *Handler) *mux.Router {
router := mux.NewRouter()
// Routes here
// Middleware registration
router.Use()
return router
}
How do I bind these to a single router and still have the middleware isolated in each group?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
