1
0
mirror of https://github.com/labstack/echo.git synced 2025-09-16 09:16:29 +02:00

Wrapper for handler in engine

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2016-03-06 11:38:52 -08:00
parent e1d789ecbb
commit af4c525be1
2 changed files with 21 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ package fasthttp
import (
"sync"
"github.com/labstack/echo"
"github.com/labstack/echo/engine"
"github.com/labstack/gommon/log"
"github.com/valyala/fasthttp"
@@ -121,3 +122,12 @@ 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,6 +4,7 @@ import (
"net/http"
"sync"
"github.com/labstack/echo"
"github.com/labstack/echo/engine"
"github.com/labstack/gommon/log"
)
@@ -116,3 +117,13 @@ 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
})
}