Skip to content

Instantly share code, notes, and snippets.

@tonespy
Created June 23, 2019 12:21
Show Gist options
  • Save tonespy/c18c872d142db051fb08a3d17f3a9de3 to your computer and use it in GitHub Desktop.
Save tonespy/c18c872d142db051fb08a3d17f3a9de3 to your computer and use it in GitHub Desktop.
Router Helper
/*
Route is a struct for handling all routes
*/
type Route struct {
Name string
Method string
Path string
HandlerFunction httprouter.Handle
}
// NewRouter is a helper function for creating new routes
func NewRouter(routes []Route) *httprouter.Router {
if len(routes) <= 0 {
return nil
}
router := httprouter.New()
for _, route := range routes {
handle := app.Logger(route.HandlerFunction)
router.Handle(route.Method, route.Path, handle)
}
return router
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment