mirror of
https://github.com/labstack/echo.git
synced 2025-07-05 00:58:47 +02:00
@ -123,11 +123,24 @@ func (s *Server) Start() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WrapHandler wraps `fasthttp.RequestHandler` into `echo.Handler`.
|
// WrapHandler wraps `fasthttp.RequestHandler` into `echo.HandlerFunc`.
|
||||||
func WrapHandler(h fasthttp.RequestHandler) echo.Handler {
|
func WrapHandler(h fasthttp.RequestHandler) echo.HandlerFunc {
|
||||||
return echo.HandlerFunc(func(c echo.Context) error {
|
return func(c echo.Context) error {
|
||||||
ctx := c.Request().Object().(*fasthttp.RequestCtx)
|
ctx := c.Request().Object().(*fasthttp.RequestCtx)
|
||||||
h(ctx)
|
h(ctx)
|
||||||
return nil
|
return nil
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapMiddleware wraps `fasthttp.RequestHandler` into `echo.MiddlewareFunc`
|
||||||
|
func WrapMiddleware(m fasthttp.RequestHandler) echo.MiddlewareFunc {
|
||||||
|
return func(next echo.Handler) echo.Handler {
|
||||||
|
return echo.HandlerFunc(func(c echo.Context) error {
|
||||||
|
ctx := c.Request().Object().(*fasthttp.RequestCtx)
|
||||||
|
if !c.Response().Committed() {
|
||||||
|
m(ctx)
|
||||||
|
}
|
||||||
|
return next.Handle(c)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,12 +118,26 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
s.pool.header.Put(resHdr)
|
s.pool.header.Put(resHdr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WrapHandler wraps `http.Handler` into `echo.Handler`.
|
// WrapHandler wraps `http.Handler` into `echo.HandlerFunc`.
|
||||||
func WrapHandler(h http.Handler) echo.Handler {
|
func WrapHandler(h http.Handler) echo.HandlerFunc {
|
||||||
return echo.HandlerFunc(func(c echo.Context) error {
|
return func(c echo.Context) error {
|
||||||
w := c.Response().Object().(http.ResponseWriter)
|
w := c.Response().Object().(http.ResponseWriter)
|
||||||
r := c.Request().Object().(*http.Request)
|
r := c.Request().Object().(*http.Request)
|
||||||
h.ServeHTTP(w, r)
|
h.ServeHTTP(w, r)
|
||||||
return nil
|
return nil
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WrapMiddleware wraps `http.Handler` into `echo.MiddlewareFunc`
|
||||||
|
func WrapMiddleware(m http.Handler) echo.MiddlewareFunc {
|
||||||
|
return func(next echo.Handler) echo.Handler {
|
||||||
|
return echo.HandlerFunc(func(c echo.Context) error {
|
||||||
|
w := c.Response().Object().(http.ResponseWriter)
|
||||||
|
r := c.Request().Object().(*http.Request)
|
||||||
|
if !c.Response().Committed() {
|
||||||
|
m.ServeHTTP(w, r)
|
||||||
|
}
|
||||||
|
return next.Handle(c)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user