feat: 更新多个模块以支持新的数据结构和日志格式

This commit is contained in:
TsMask
2025-02-20 10:08:27 +08:00
parent 045a2b6b01
commit f3c33b31ac
272 changed files with 13246 additions and 15885 deletions

View File

@@ -7,8 +7,8 @@ import (
"time"
"be.ems/src/framework/logger"
"be.ems/src/framework/resp"
"be.ems/src/framework/utils/generate"
"be.ems/src/framework/vo/result"
"be.ems/src/modules/ws/model"
"github.com/gorilla/websocket"
)
@@ -53,7 +53,7 @@ func (s *WS) UpgraderWs(w http.ResponseWriter, r *http.Request) *websocket.Conn
// groupIDs 用户订阅组
// conn ws连接实例
// childConn 子连接实例
func (s *WS) ClientCreate(uid string, groupIDs []string, conn *websocket.Conn, childConn any) *model.WSClient {
func (s *WS) ClientCreate(uid int64, groupIDs []string, conn *websocket.Conn, childConn any) *model.WSClient {
// clientID也可以用其他方式生成只要能保证在所有服务端中都能保证唯一即可
clientID := generate.Code(16)
@@ -72,7 +72,7 @@ func (s *WS) ClientCreate(uid string, groupIDs []string, conn *websocket.Conn, c
wsClients.Store(clientID, wsClient)
// 存入用户持有客户端
if uid != "" {
if uid > 0 {
if v, ok := wsUsers.Load(uid); ok {
uidClientIds := v.(*[]string)
*uidClientIds = append(*uidClientIds, clientID)
@@ -82,7 +82,7 @@ func (s *WS) ClientCreate(uid string, groupIDs []string, conn *websocket.Conn, c
}
// 存入用户订阅组
if uid != "" && len(groupIDs) > 0 {
if uid > 0 && len(groupIDs) > 0 {
for _, groupID := range groupIDs {
if v, ok := wsGroup.Load(groupID); ok {
groupClientIds := v.(*[]string)
@@ -112,7 +112,7 @@ func (s *WS) ClientClose(clientID string) {
}()
// 客户端断线时自动踢出Uid绑定列表
if client.BindUid != "" {
if client.BindUid > 0 {
if v, ok := wsUsers.Load(client.BindUid); ok {
uidClientIds := v.(*[]string)
if len(*uidClientIds) > 0 {
@@ -160,7 +160,7 @@ func (s *WS) ClientReadListen(wsClient *model.WSClient, receiveFn func(*model.WS
// 读取消息
messageType, msg, err := wsClient.Conn.ReadMessage()
if err != nil {
logger.Warnf("ws ReadMessage UID %s err: %s", wsClient.BindUid, err.Error())
logger.Warnf("ws ReadMessage UID %d err: %s", wsClient.BindUid, err.Error())
s.ClientClose(wsClient.ID)
return
}
@@ -170,7 +170,7 @@ func (s *WS) ClientReadListen(wsClient *model.WSClient, receiveFn func(*model.WS
if messageType == websocket.TextMessage {
var reqMsg model.WSRequest
if err := json.Unmarshal(msg, &reqMsg); err != nil {
msgByte, _ := json.Marshal(result.ErrMsg("message format json error"))
msgByte, _ := json.Marshal(resp.ErrMsg("message format json error"))
wsClient.MsgChan <- msgByte
continue
}
@@ -189,7 +189,7 @@ func (s *WS) ClientWriteListen(wsClient *model.WSClient) {
}
}()
// 发客户端id确认是否连接
msgByte, _ := json.Marshal(result.OkData(map[string]string{
msgByte, _ := json.Marshal(resp.OkData(map[string]string{
"clientId": wsClient.ID,
}))
wsClient.MsgChan <- msgByte
@@ -203,7 +203,7 @@ func (s *WS) ClientWriteListen(wsClient *model.WSClient) {
// 发送消息
err := wsClient.Conn.WriteMessage(websocket.TextMessage, msg)
if err != nil {
logger.Warnf("ws WriteMessage UID %s err: %s", wsClient.BindUid, err.Error())
logger.Warnf("ws WriteMessage UID %d err: %s", wsClient.BindUid, err.Error())
s.ClientClose(wsClient.ID)
return
}