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

WrapMiddleware for echo.Handler

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2016-03-07 07:55:26 -08:00
parent 4f08fed018
commit b6deec4897

12
echo.go
View File

@ -471,6 +471,18 @@ func (binder) Bind(i interface{}, c Context) (err error) {
return
}
// WrapMiddleware wrap `echo.Handler` into `echo.MiddlewareFunc`.
func WrapMiddleware(h Handler) MiddlewareFunc {
return func(next Handler) Handler {
return HandlerFunc(func(c Context) error {
if !c.Response().Committed() {
h.Handle(c)
}
return next.Handle(c)
})
}
}
func handlerName(h Handler) string {
t := reflect.ValueOf(h).Type()
if t.Kind() == reflect.Func {