Created
June 23, 2019 12:21
-
-
Save tonespy/c18c872d142db051fb08a3d17f3a9de3 to your computer and use it in GitHub Desktop.
Router Helper
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
/* | |
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