Skip to content

Instantly share code, notes, and snippets.

@rossedman
Last active May 8, 2020 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rossedman/179b976abde3fbb2db2b718b469ca29f to your computer and use it in GitHub Desktop.
Save rossedman/179b976abde3fbb2db2b718b469ca29f to your computer and use it in GitHub Desktop.
Gorrila Mux Router Mounting
package main
func main() {
r := mux.NewRouter()
mount(r, "/api/v1", handler.Router(), auth)
...
}
// mount will take routers from a handler and add it with a pathprefix
// mount will take routers from a handler and add it with a pathprefix
func mount(r *mux.Router, path string, handler http.Handler, middleware mux.MiddlewareFunc) {
r.PathPrefix(path).Handler(
http.StripPrefix(
strings.TrimSuffix(path, "/"),
middleware(handler),
),
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment