main
kzkzzzz 2024-06-01 18:47:42 +08:00
parent 7fe58f3725
commit 2b7c5848fe
1 changed files with 22 additions and 0 deletions

22
common.go Normal file
View File

@ -0,0 +1,22 @@
package mycommon
import (
"git.makemake.in/kzkzzzz/mycommon/mylog"
"runtime/debug"
)
func SafeFn(fn func()) {
defer func() {
if err := recover(); err != nil {
mylog.Errorf("panic: %s\n%s", err, string(debug.Stack()))
}
}()
fn()
}
func SafeGo(fn func()) {
go func() {
SafeFn(fn)
}()
}