Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apart code of chapter 6 not work #13

Open
johnsmeeth opened this issue Feb 1, 2018 · 0 comments
Open

apart code of chapter 6 not work #13

johnsmeeth opened this issue Feb 1, 2018 · 0 comments

Comments

@johnsmeeth
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant