Ai
1 Star 0 Fork 1

flanche/echo

forked from guapian/echo 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
recover.go 763 Bytes
一键复制 编辑 原始数据 按行查看 历史
Vishal Rana 提交于 2016-02-09 14:17 +08:00 . Wrappers for handler and middleware
package middleware
import (
"fmt"
"runtime"
"github.com/labstack/echo"
)
// Recover returns a middleware which recovers from panics anywhere in the chain
// and handles the control to the centralized HTTPErrorHandler.
func Recover() echo.MiddlewareFunc {
return func(h echo.HandlerFunc) echo.HandlerFunc {
// TODO: Provide better stack trace `https://github.com/go-errors/errors` `https://github.com/docker/libcontainer/tree/master/stacktrace`
return func(c echo.Context) error {
defer func() {
if err := recover(); err != nil {
trace := make([]byte, 1<<16)
n := runtime.Stack(trace, true)
c.Error(fmt.Errorf("panic recover\n %v\n stack trace %d bytes\n %s",
err, n, trace[:n]))
}
}()
return h.Handle(c)
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/flanche/echo.git
git@gitee.com:flanche/echo.git
flanche
echo
echo
v2.0.0-apha.1

搜索帮助