Last active
May 8, 2020 21:38
-
-
Save rossedman/179b976abde3fbb2db2b718b469ca29f to your computer and use it in GitHub Desktop.
Gorrila Mux Router Mounting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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