spbooks / go1

Code archive for the book Level Up Your Web Apps With Go
109 stars 53 forks source link

In chapter six, middleware doesn't work #4

Open mnazarani opened 8 years ago

mnazarani commented 8 years ago

Any path added to secureRouter returns 404 - page not found error.

snikch commented 8 years ago

Hey @mnazarani, are you able to post your code here so I can check it out for you? Cheers

dmikalova commented 8 years ago

I am getting the same error in chapter 7. Running the code from 7-3 of your repo gives me: ./main.go:69: cannot use func literal (type func(http.ResponseWriter, *http.Request)) as type http.Handler in assignment: func(http.ResponseWriter, *http.Request) does not implement http.Handler (missing ServeHTTP method)

I think from following the book I arrived at func NewRouter() *httprouter.Router { router := httprouter.New() return router } which does compile but gives the 404s mentioned above.

dmikalova commented 8 years ago

Finaslly had more time to track this down - the issue is with vendoring - if you use godeps (as stated in the book) then it works. You may want to add a readme stating as much.

snikch commented 8 years ago

Good news @dmikalova. Sorry I missed your previous comment!

snikch commented 8 years ago

Just checking, when you say adding a readme, you mean to this repo?

dmikalova commented 8 years ago

Yeah, to the top level just so new readers don't end up as stupid as me :)

snikch commented 8 years ago

:+1: