From e0b851439942efd364803ce465eb14e493cf4839 Mon Sep 17 00:00:00 2001 From: zyj <18107291228@163.com> Date: Tue, 23 Sep 2025 17:39:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=9E=E6=8E=A5=E5=82=A8?= =?UTF-8?q?=E5=AD=98=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/websocks.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/api/websocks.go b/api/websocks.go index 2556e40..c80c27f 100644 --- a/api/websocks.go +++ b/api/websocks.go @@ -79,7 +79,10 @@ func (w *Websocks) Init(ctx *gin.Context) { // 将保存连接状态 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() log.Printf("客户端已连接: %s", conn.RemoteAddr()) w.MessageHandle(conn, deviceLoginInfo)