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