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
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:
route := 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
).
© 2022 - 2024 — McMap. All rights reserved.