1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
// +build gingonic,!gorillamux,!echo
package routing
import (
"net/http"
"github.com/gin-gonic/gin"
)
type ginRouter struct {
router *gin.Engine
}
func (g ginRouter) Handler() http.Handler {
return g.router
}
func (g ginRouter) Handle(protocol, route string, handler HandlerFunc) {
wrappedCallback := func(c *gin.Context) {
params := map[string]string{}
for _, p := range c.Params {
params[p.Key] = p.Value
}
handler(c.Writer, c.Request, params)
}
g.router.Handle(protocol, route, wrappedCallback)
}
//Gin creates a new api2go router to use with the gin framework
func Gin(g *gin.Engine) Routeable {
return &ginRouter{router: g}
}
|