File: echo.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 (37 lines) | stat: -rw-r--r-- 693 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
36
37
// +build echo,!gorillamux,!gingonic

package routing

import (
	"net/http"

	"github.com/labstack/echo"
)

type echoRouter struct {
	echo *echo.Echo
}

func (e echoRouter) Handler() http.Handler {
	return e.echo
}

func (e echoRouter) Handle(protocol, route string, handler HandlerFunc) {
	echoHandlerFunc := func(c echo.Context) error {
		params := map[string]string{}

		for i, p := range c.ParamNames() {
			params[p] = c.ParamValues()[i]
		}

		handler(c.Response(), c.Request(), params)

		return nil
	}
	e.echo.Add(protocol, route, echoHandlerFunc)
}

// Echo created a new api2go router to use with the echo framework
func Echo(e *echo.Echo) Routeable {
	return &echoRouter{echo: e}
}