Created
May 23, 2019 22:31
-
-
Save ramirez7/095f455f47e0bb3a100a466ecbab0728 to your computer and use it in GitHub Desktop.
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
// routes1.go | |
func Routes1(mux *http.ServeMux) { | |
mux.Handle("/route1/a", handler1A) | |
mux.Handle("/route1/b", handler1B) | |
mux.Handle("/route1/c", handler1C) | |
} | |
// routes2.go | |
func Routes2(mux *http.ServeMux) { | |
mux.Handle("/route2/x", handler2X) | |
mux.Handle("/route2/y", handler2Y) | |
mux.Handle("/route2/z", handler2Z) | |
} | |
// combine_routes.go | |
func CombineRoutes(routes func(mux *http.ServeMux)...) *http.ServeMux { | |
mux := http.NewServeMux() | |
for r := range routes { | |
r(mux) | |
} | |
return mux | |
} | |
// server.go | |
mux := CombineRoutes(Routes1, Routes2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment