go-web
go-web copied to clipboard
apart code of chapter 6 not work
Hi @shijuvar I've read this example in chapter 6
router := mux.NewRouter()
adminRoutes := mux.NewRouter()
// add admin routes here
// Create a new negroni for the admin middleware
router.Handle("/admin", negroni.New(
Middleware1,
Middleware2,
negroni.Wrap(adminRoutes),
))
But this piece of code
router.Handle("/admin", negroni.New(
Middleware1,
Middleware2,
negroni.Wrap(adminRoutes),
))
seem not work. When visit url http://localhost:8080/admin or http://localhost:8080/admin/dashboard
both seem the handlers for /admin not executed.
This is my handlers for /admin route
// adminRouter routes
adminRoutes.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Println("/admin")
fmt.Fprintf(w, "/admin")
}))
adminRoutes.Handle("/dashboard", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Println("/admin/dashboard")
fmt.Fprintf(w, "dashboard page")
}))
What wrong with my code? Your book so great. Thanks