mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
Fixed sync.Pool
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
0731959a98
commit
3cd1d5be65
10
echo.go
10
echo.go
@ -55,8 +55,12 @@ type (
|
||||
message string
|
||||
}
|
||||
|
||||
// Middleware interface{}
|
||||
Middleware interface {
|
||||
Process(HandlerFunc) HandlerFunc
|
||||
}
|
||||
|
||||
MiddlewareFunc func(HandlerFunc) HandlerFunc
|
||||
|
||||
// Handler interface{}
|
||||
HandlerFunc func(Context) error
|
||||
|
||||
@ -224,6 +228,10 @@ func New() (e *Echo) {
|
||||
return
|
||||
}
|
||||
|
||||
func (f MiddlewareFunc) Process(h HandlerFunc) HandlerFunc {
|
||||
return f(h)
|
||||
}
|
||||
|
||||
// Router returns router.
|
||||
func (e *Echo) Router() *Router {
|
||||
return e.router
|
||||
|
@ -61,15 +61,15 @@ func (s *Server) Start() {
|
||||
s.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// Request
|
||||
req := s.pool.request.Get().(*Request)
|
||||
reqHdr := s.pool.request.Get().(*Header)
|
||||
reqURL := s.pool.request.Get().(*URL)
|
||||
reqHdr := s.pool.header.Get().(*Header)
|
||||
reqURL := s.pool.url.Get().(*URL)
|
||||
reqHdr.reset(r.Header)
|
||||
reqURL.reset(r.URL)
|
||||
req.reset(r, reqHdr, reqURL)
|
||||
|
||||
// Response
|
||||
res := s.pool.request.Get().(*Response)
|
||||
resHdr := s.pool.request.Get().(*Header)
|
||||
res := s.pool.response.Get().(*Response)
|
||||
resHdr := s.pool.header.Get().(*Header)
|
||||
res.reset(w, reqHdr)
|
||||
|
||||
s.handler(req, res)
|
||||
|
@ -19,7 +19,7 @@ const (
|
||||
//
|
||||
// For valid credentials it calls the next handler.
|
||||
// For invalid credentials, it sends "401 - Unauthorized" response.
|
||||
func BasicAuth(fn BasicValidateFunc) MiddlewareFunc {
|
||||
func BasicAuth(fn BasicValidateFunc) echo.MiddlewareFunc {
|
||||
return func(h echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
// Skip WebSocket
|
||||
|
@ -48,7 +48,7 @@ var writerPool = sync.Pool{
|
||||
|
||||
// Gzip returns a middleware which compresses HTTP response using gzip compression
|
||||
// scheme.
|
||||
func Gzip() MiddlewareFunc {
|
||||
func Gzip() echo.MiddlewareFunc {
|
||||
return func(h echo.HandlerFunc) echo.HandlerFunc {
|
||||
scheme := "gzip"
|
||||
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"github.com/labstack/gommon/color"
|
||||
)
|
||||
|
||||
func Log() MiddlewareFunc {
|
||||
func Log() echo.MiddlewareFunc {
|
||||
return func(h echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
req := c.Request()
|
||||
|
@ -1,15 +0,0 @@
|
||||
package middleware
|
||||
|
||||
import "github.com/labstack/echo"
|
||||
|
||||
type (
|
||||
Middleware interface {
|
||||
Process(echo.HandlerFunc) echo.HandlerFunc
|
||||
}
|
||||
|
||||
MiddlewareFunc func(echo.HandlerFunc) echo.HandlerFunc
|
||||
)
|
||||
|
||||
func (f MiddlewareFunc) Process(h echo.HandlerFunc) echo.HandlerFunc {
|
||||
return f(h)
|
||||
}
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
// Recover returns a middleware which recovers from panics anywhere in the chain
|
||||
// and handles the control to the centralized HTTPErrorHandler.
|
||||
func Recover() MiddlewareFunc {
|
||||
func Recover() echo.MiddlewareFunc {
|
||||
return func(h echo.HandlerFunc) echo.HandlerFunc {
|
||||
// TODO: Provide better stack trace `https://github.com/go-errors/errors` `https://github.com/docker/libcontainer/tree/master/stacktrace`
|
||||
return func(c echo.Context) error {
|
||||
|
Loading…
Reference in New Issue
Block a user