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.

Revisions

  1. tonespy created this gist Jun 23, 2019.
    25 changes: 25 additions & 0 deletions router.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    /*
    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
    }