go-zero/core/rescue/recover.go

17 lines
309 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package rescue
import "github.com/zeromicro/go-zero/core/logx"
2020-07-26 17:09:05 +08:00
// Recover is used with defer to do cleanup on panics.
// Use it like:
// defer Recover(func() {})
2020-07-26 17:09:05 +08:00
func Recover(cleanups ...func()) {
for _, cleanup := range cleanups {
cleanup()
}
if p := recover(); p != nil {
logx.ErrorStack(p)
}
}