Last active
May 8, 2020 21:38
-
-
Save rossedman/179b976abde3fbb2db2b718b469ca29f to your computer and use it in GitHub Desktop.
Revisions
-
rossedman revised this gist
May 8, 2020 . 1 changed file with 8 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,10 +7,12 @@ func main() { } // 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), ), ) } -
rossedman revised this gist
May 8, 2020 . 1 changed file with 3 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -8,13 +8,9 @@ func main() { // 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) { s := r.PathPrefix(path).Subrouter() s.Handle("/", handler) if len(middleware) > 0 { s.Use(middleware...) } } -
rossedman created this gist
May 8, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ 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 func mount(r *mux.Router, path string, handler http.Handler, middleware ...mux.MiddlewareFunc) { r.PathPrefix(path).Handler( http.StripPrefix( strings.TrimSuffix(path, "/"), handler, ), ) if len(middleware) > 0 { r.Use(middleware...) } }