修改连接储存方法

This commit is contained in:
zyj
2025-09-23 17:39:06 +08:00
parent 1472b1c307
commit e0b8514399

View File

@@ -79,7 +79,10 @@ func (w *Websocks) Init(ctx *gin.Context) {
// 将保存连接状态 // 将保存连接状态
ClientsMu.Lock() ClientsMu.Lock()
Clients[TokenStatus.UserId] = map[int64]*websocket.Conn{deviceLoginInfo.ID: conn} if _, ok := Clients[TokenStatus.UserId]; !ok {
Clients[TokenStatus.UserId] = make(map[int64]*websocket.Conn)
}
Clients[TokenStatus.UserId][deviceLoginInfo.ID] = conn
ClientsMu.Unlock() ClientsMu.Unlock()
log.Printf("客户端已连接: %s", conn.RemoteAddr()) log.Printf("客户端已连接: %s", conn.RemoteAddr())
w.MessageHandle(conn, deviceLoginInfo) w.MessageHandle(conn, deviceLoginInfo)