File: gingonic.go

package info (click to toggle)
golang-github-manyminds-api2go 1.0-RC4-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 552 kB
  • sloc: sh: 23; makefile: 3
file content (35 lines) | stat: -rw-r--r-- 659 bytes parent folder | download | duplicates (2)
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}
}