Skip to content

apart code of chapter 6 not work #13

@johnsmeeth

Description

@johnsmeeth

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions