first commit

This commit is contained in:
Yangtao
2025-11-18 17:48:20 +08:00
commit 6e56cab848
196 changed files with 65809 additions and 0 deletions

26
pkg/tools/safe.go Normal file
View File

@ -0,0 +1,26 @@
package tools
import (
"runtime/debug"
"servicebase/pkg/log"
)
func Recover(cleanups ...func()) {
for _, cleanup := range cleanups {
cleanup()
}
if p := recover(); p != nil {
log.ErrorF("occur panic: [%+v], stack info [%s]", p, debug.Stack())
}
}
func RunSafe(fn func()) {
defer Recover()
fn()
}
func GoSafe(fn func()) {
go RunSafe(fn)
}