Skip to content

Instantly share code, notes, and snippets.

@ramirez7
Created May 23, 2019 22:31
Show Gist options
  • Save ramirez7/095f455f47e0bb3a100a466ecbab0728 to your computer and use it in GitHub Desktop.
Save ramirez7/095f455f47e0bb3a100a466ecbab0728 to your computer and use it in GitHub Desktop.
// 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