1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-24 20:14:31 +02:00

Fixed import cycle

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2016-03-06 11:43:40 -08:00
parent af4c525be1
commit 569d72cd76
4 changed files with 22 additions and 23 deletions

21
echo.go
View File

@ -14,6 +14,8 @@ import (
"encoding/xml"
"github.com/valyala/fasthttp"
"github.com/labstack/echo/engine"
"github.com/labstack/gommon/log"
)
@ -471,6 +473,25 @@ func (binder) Bind(i interface{}, c Context) (err error) {
return
}
// WrapStandardHandler wraps `http.Handler` into `echo.Handler`.
func WrapStandardHandler(h http.Handler) Handler {
return HandlerFunc(func(c Context) error {
w := c.Response().Object().(http.ResponseWriter)
r := c.Request().Object().(*http.Request)
h.ServeHTTP(w, r)
return nil
})
}
// WrapFastHTTPHandler wraps `fasthttp.RequestHandler` into `echo.Handler`.
func WrapFastHTTPHandler(h fasthttp.RequestHandler) Handler {
return HandlerFunc(func(c Context) error {
ctx := c.Request().Object().(*fasthttp.RequestCtx)
h(ctx)
return nil
})
}
func handlerName(h Handler) string {
t := reflect.ValueOf(h).Type()
if t.Kind() == reflect.Func {

View File

@ -5,7 +5,6 @@ package fasthttp
import (
"sync"
"github.com/labstack/echo"
"github.com/labstack/echo/engine"
"github.com/labstack/gommon/log"
"github.com/valyala/fasthttp"
@ -122,12 +121,3 @@ func (s *Server) Start() {
s.logger.Fatal(fasthttp.ListenAndServe(addr, handler))
}
}
// WrapHandler wraps `fasthttp.RequestHandler` into `echo.Handler`.
func WrapHandler(h fasthttp.RequestHandler) echo.Handler {
return echo.HandlerFunc(func(c echo.Context) error {
c := c.Request().Object().(*fasthttp.RequestCtx)
h(c)
return nil
})
}

View File

@ -4,7 +4,6 @@ import (
"net/http"
"sync"
"github.com/labstack/echo"
"github.com/labstack/echo/engine"
"github.com/labstack/gommon/log"
)
@ -117,13 +116,3 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.pool.response.Put(res)
s.pool.header.Put(resHdr)
}
// WrapHandler wraps `http.Handler` into `echo.Handler`.
func WrapHandler(h http.Handler) echo.Handler {
return echo.HandlerFunc(func(c echo.Context) error {
w := c.Response().Object().(http.ResponseWriter)
r := c.Request().Object().(*http.Request)
h.ServeHTTP(w, r)
return nil
})
}

View File

@ -8,7 +8,6 @@ import (
"github.com/labstack/echo"
"github.com/labstack/echo/test"
"github.com/labstack/gommon/log"
"github.com/stretchr/testify/assert"
)
@ -57,7 +56,7 @@ func TestLoggerIPAddress(t *testing.T) {
rec := test.NewResponseRecorder()
c := echo.NewContext(req, rec, e)
buf := new(bytes.Buffer)
e.Logger().(*log.Logger).SetOutput(buf)
e.Logger().SetOutput(buf)
ip := "127.0.0.1"
h := Logger()(echo.HandlerFunc(func(c echo.Context) error {
return c.String(http.StatusOK, "test")