1、消息提示

This commit is contained in:
2025-07-15 16:43:50 +08:00
parent ab50cf0dfe
commit 2e35d55838
21 changed files with 1436 additions and 6 deletions

View File

@ -27,3 +27,8 @@ const (
//系统配置缓存
Config = "config:%s"
)
const (
// 钱包白名单缓存
WalletWhiteListKey = "wallet_white_list"
)

View File

@ -0,0 +1,11 @@
package global
import "go-admin/app/websocket"
var WebSocketHub *websocket.Hub
type AlarmLogNotice struct {
MachineId string `json:"machineId"`
BiosId string `json:"biosId"`
Content string `json:"content"`
}

44
common/helper/safego.go Normal file
View File

@ -0,0 +1,44 @@
package helper
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) // 执行传入的函数
}()
}