mirror of
https://github.com/labstack/echo.git
synced 2025-04-21 12:17:04 +02:00
Fixed import cycle
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
af4c525be1
commit
a00ae2e691
21
echo.go
21
echo.go
@ -14,6 +14,8 @@ import (
|
|||||||
|
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
|
||||||
"github.com/labstack/echo/engine"
|
"github.com/labstack/echo/engine"
|
||||||
"github.com/labstack/gommon/log"
|
"github.com/labstack/gommon/log"
|
||||||
)
|
)
|
||||||
@ -471,6 +473,25 @@ func (binder) Bind(i interface{}, c Context) (err error) {
|
|||||||
return
|
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 {
|
func handlerName(h Handler) string {
|
||||||
t := reflect.ValueOf(h).Type()
|
t := reflect.ValueOf(h).Type()
|
||||||
if t.Kind() == reflect.Func {
|
if t.Kind() == reflect.Func {
|
||||||
|
@ -5,7 +5,6 @@ package fasthttp
|
|||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/labstack/echo"
|
|
||||||
"github.com/labstack/echo/engine"
|
"github.com/labstack/echo/engine"
|
||||||
"github.com/labstack/gommon/log"
|
"github.com/labstack/gommon/log"
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
@ -122,12 +121,3 @@ func (s *Server) Start() {
|
|||||||
s.logger.Fatal(fasthttp.ListenAndServe(addr, handler))
|
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
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/labstack/echo"
|
|
||||||
"github.com/labstack/echo/engine"
|
"github.com/labstack/echo/engine"
|
||||||
"github.com/labstack/gommon/log"
|
"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.response.Put(res)
|
||||||
s.pool.header.Put(resHdr)
|
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
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user