diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index 389a01e0..2b5f27fa 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -56,7 +56,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindOne(l.ctx, req.MerchantType) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the merchant category is not exists") + return resp.SetStatusWithMessage(basic.CodeOK, "the merchant category is not exists", []interface{}{}) } logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get merchant category") @@ -66,7 +66,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindDefualtOne(l.ctx) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the default merchant category is not exists") + return resp.SetStatusWithMessage(basic.CodeOK, "the default merchant category is not exists", []interface{}{}) } logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get default merchant category") diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index b62f4dca..7c97ec08 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -59,7 +59,7 @@ var ( CheckOrigin: func(r *http.Request) bool { return true }, - //写的缓存池 + //写的缓冲队列 WriteBufferPool: &buffPool, //是否支持压缩 EnableCompression: false, @@ -75,8 +75,8 @@ type wsConnectItem struct { closeChan chan struct{} //ws连接关闭chan(基本属性) isClose bool //是否已经关闭(基本属性) uniqueId string //ws连接唯一标识(基本属性) - inChan chan []byte //接受消息缓冲池(基本属性) - outChan chan []byte //要发送回客户端的消息缓冲池(基本属性) + inChan chan []byte //接受消息缓冲队列(基本属性) + outChan chan []byte //要发送回客户端的消息缓冲队列(基本属性) mutex sync.Mutex //互斥锁(基本属性) userId int64 //用户id(基本属性) guestId int64 //游客id(基本属性) @@ -268,7 +268,7 @@ func (w *wsConnectItem) close() { logx.Info("###websocket:", w.uniqueId, " uid:", w.userId, " gid:", w.guestId, " is closed") } -// 读取出口缓冲池数据输出返回给浏览器端 +// 读取出口缓冲队列数据输出返回给浏览器端 func (w *wsConnectItem) writeLoop() { defer func() { if err := recover(); err != nil { @@ -289,7 +289,7 @@ func (w *wsConnectItem) writeLoop() { } } -// 接受客户端发来的消息并写入入口缓冲池 +// 接受客户端发来的消息并写入入口缓冲队列 func (w *wsConnectItem) readLoop() { defer func() { if err := recover(); err != nil { @@ -300,7 +300,7 @@ func (w *wsConnectItem) readLoop() { select { case <-w.closeChan: //如果关闭了 return - default: + default: //收取消息 msgType, data, err := w.conn.ReadMessage() if err != nil { logx.Error("接受信息错误:", err) @@ -308,10 +308,9 @@ func (w *wsConnectItem) readLoop() { w.close() return } - //ping的消息不处理 - if msgType != websocket.PingMessage { - //消息传入缓冲通道 - w.inChan <- data + //ping/pong/close的消息不处理 + if msgType != websocket.PingMessage && msgType != websocket.PongMessage && msgType != websocket.CloseMessage { + w.sendToInChan(data) } } } @@ -334,7 +333,7 @@ func (w *wsConnectItem) sendLoop() { } } -// 把要传递给客户端的数据放入出口缓冲池 +// 把要传递给客户端的数据放入出口缓冲队列 func (w *wsConnectItem) sendToOutChan(data []byte) { select { case <-w.closeChan: @@ -346,6 +345,18 @@ func (w *wsConnectItem) sendToOutChan(data []byte) { } } +// 发送接受到的消息到入口缓冲队列中 +func (w *wsConnectItem) sendToInChan(data []byte) { + select { + case <-w.closeChan: //关闭了 + return + case w.inChan <- data: + return + case <-time.After(time.Second * 3): //3秒超时丢弃 + return + } +} + // 格式化为websocket标准返回格式 func (w *wsConnectItem) respondDataFormat(msgType constants.Websocket, data interface{}) []byte { d := websocket_data.DataTransferData{ @@ -356,7 +367,7 @@ func (w *wsConnectItem) respondDataFormat(msgType constants.Websocket, data inte return b } -// 处理入口缓冲池中不同类型的数据(分发处理) +// 处理入口缓冲队列中不同类型的数据(分发处理) func (w *wsConnectItem) dealwithReciveData(data []byte) { var parseInfo websocket_data.DataTransferData if err := json.Unmarshal(data, &parseInfo); err != nil { diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index b2ac63b7..123545ff 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -44,19 +44,19 @@ type renderTask struct { uploadUnityRenderImageTakesTime int64 //上传unity渲染结果图时间 } -// 发送到渲染缓冲池 +// 发送到渲染缓冲队列 func (w *wsConnectItem) sendToRenderChan(data []byte) { select { case <-w.closeChan: //已经关闭 return - case w.extendRenderProperty.renderChan <- data: //发入到缓冲池 + case w.extendRenderProperty.renderChan <- data: //发入到缓冲队列 return - case <-time.After(time.Second * 3): //三秒没进入缓冲池就丢弃 + case <-time.After(time.Second * 3): //三秒没进入缓冲队列就丢弃 return } } -// 渲染发送到组装数据组装数据(缓冲池) +// 渲染发送到组装数据组装数据(缓冲队列) func (w *wsConnectItem) renderImage() { for { select {