recover
Recover中间件,用于捕获各种panic异常,避免程序异常退出,但建议自定义recover中间件,在获取到此类异常时,发送告警后做graceful restart。
Example
package main
import (
"errors"
"github.com/vicanso/elton"
"github.com/vicanso/elton/middleware"
)
func main() {
e := elton.New()
e.Use(middleware.NewRecover())
e.GET("/", func(c *elton.Context) (err error) {
panic(errors.New("abcd"))
})
err := e.ListenAndServe(":3000")
if err != nil {
panic(err)
}
}