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

package api2go

import (
	"log"
	"net/http"

	"github.com/labstack/echo"
	"github.com/manyminds/api2go/routing"
)

func customHTTPErrorHandler(err error, c echo.Context) {
	if he, ok := err.(*echo.HTTPError); ok {
		if he == echo.ErrMethodNotAllowed {
			handleError(NewHTTPError(he, "Method Not Allowed", http.StatusMethodNotAllowed), c.Response(), c.Request(), defaultContentTypHeader)
		}
	}
}

func newTestRouter() routing.Routeable {
	e := echo.New()
	// not found handler, this needs to be fixed as well: see: https://github.com/manyminds/api2go/issues/301
	e.HTTPErrorHandler = customHTTPErrorHandler
	return routing.Echo(e)
}

func init() {
	log.Println("Testing with echo router")
}