1 Star 0 Fork 0

Stefan/go-zero

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
recoverhandler.go 528 Bytes
一键复制 编辑 原始数据 按行查看 历史
Stefan 提交于 2025-06-11 18:20 +08:00 . fix import package
package handler
import (
"fmt"
"net/http"
"runtime/debug"
"gitee.com/emmm_admin/go-zero/rest/internal"
)
// RecoverHandler returns a middleware that recovers if panic happens.
func RecoverHandler(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func() {
if result := recover(); result != nil {
internal.Error(r, fmt.Sprintf("%v\n%s", result, debug.Stack()))
w.WriteHeader(http.StatusInternalServerError)
}
}()
next.ServeHTTP(w, r)
})
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/stefan886/go-zero.git
git@gitee.com:stefan886/go-zero.git
stefan886
go-zero
go-zero
45236c288c2b

搜索帮助