How to filter some path from gorilla mux.Router

Viewed 898

I would like to match only some routes from a mux.Router, and use the same handler for all the others. How can I do this?

i.e.: having these paths:

/general/baz/bro
/general/foo/bar
/general/unknown

I would like to match the first with a specific handler, and all the others with a default handler.

I've tried with no success something like:

r.Methods("GET").PathPrefix("/general").Handler(defaultHandler)
r.Methods("GET").Path("/general/baz/bro").Handler(bazBroHandler)

I was expecting the bazBroHandler handling the /general/baz/bro path, and the defaultHandler all the other starting with /general

2 Answers
Related