What is the proper syntax to create a simple "match anything" handler?
mux.NewRouter().StrictSlash(true).Path("/")....
The above code seems to strictly match /
and /foo
won't get matched
This should work:
router := mux.NewRouter().PathPrefix("/")
You can use mux.Route.HandlerFunc
together with mux.Router.PathPrefix
:
r := mux.NewRouter()
// route catalog to catalogHandler:
r.HandleFunc("/catalog/{id}", catalogHandler)
// route everything else to defaultHandler:
r.PathPrefix("/").HandlerFunc(defaultHandler)
Note the difference in names (HandlerFunc
vs HandleFunc
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With