justinas / alice

Painless middleware chaining for Go

Home Page:https://godoc.org/github.com/justinas/alice

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to deal with recovery middleware?

Rick1125 opened this issue · comments

You said Alice make no garentees with middleware's behaviors,
it will stop the chain when panic,
so how can I make recovery as a middleware?

The net/http server will recover from panics automatically (see the relevant code).

However, if you'd like to roll out your own recovery middleware, it should kick in as early as possible in the request lifecycle. Ideally, it should be the first in the chain.

alice.New(recoveryMiddleware, ...).Then(handler)