Skip to content

Commit

Permalink
WrapMiddleware for echo.Handler
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Rana <[email protected]>
  • Loading branch information
vishr committed Mar 7, 2016
1 parent 4f08fed commit b6deec4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b6deec4

Please sign in to comment.