1、sms取消号码

This commit is contained in:
2025-07-25 17:22:34 +08:00
parent 854d7bee0c
commit f552188ff9
13 changed files with 393 additions and 190 deletions

View File

@ -0,0 +1,44 @@
package utility
import (
"fmt"
"runtime"
"runtime/debug"
"strings"
"github.com/go-admin-team/go-admin-core/logger"
)
// SafeGo 安全地启动一个 goroutine捕获 panic
func SafeGo(fn func()) {
go func() {
defer func() {
if r := recover(); r != nil {
// 记录 Goroutine ID、panic 信息和堆栈
logger.Error(fmt.Sprintf("Recovered from panic in Goroutine %s: %v\nStack Trace:\n%s", GetGoroutineID(), r, string(debug.Stack())))
}
}()
fn()
}()
}
// 获取 Goroutine ID
func GetGoroutineID() string {
buf := make([]byte, 64)
n := runtime.Stack(buf, false)
stack := string(buf[:n])
// 提取 Goroutine ID
id := strings.Split(stack, " ")[1]
return id
}
func SafeGoParam[T any](fn func(T), param T) {
go func() {
defer func() {
if r := recover(); r != nil {
logger.Error(fmt.Sprintf(" SafeGoParam Recovered from panic in Goroutine %s: %v\nStack Trace:\n%s", GetGoroutineID(), r, string(debug.Stack())))
}
}()
fn(param) // 执行传入的函数
}()
}