From b6deec48978d570667b16f33fa5f74c8b161e85c Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Mon, 7 Mar 2016 07:55:26 -0800 Subject: [PATCH] WrapMiddleware for echo.Handler Signed-off-by: Vishal Rana --- echo.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/echo.go b/echo.go index fe0cb8b4..a5ec5f00 100644 --- a/echo.go +++ b/echo.go @@ -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 {