This commit is contained in:
tamakyi
2026-09-08 10:10:44 +08:00
commit 2ed27dd55e
288 changed files with 67061 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
package shared
import (
"github.com/sirupsen/logrus"
)
// SafeGo 在独立 goroutine 中执行 fn 并捕获 panic,防止任一 goroutine
// panic 未恢复导致整个进程崩溃(Go 默认行为:未恢复的 panic 终止进程)。
//
// 用法:shared.SafeGo(func() { ... })
func SafeGo(fn func()) {
go func() {
defer func() {
if r := recover(); r != nil {
logrus.WithField("panic", r).Error("goroutine panic recovered")
}
}()
fn()
}()
}