This commit is contained in:
苏尹岚
2020-08-20 13:45:13 +08:00
parent dd954b5442
commit c7be6b3cbe

View File

@@ -132,28 +132,29 @@ func (c *EventController) TestWebsocket() {
//将当前客户端放入map中 //将当前客户端放入map中
clients[ws] = true clients[ws] = true
m := &model.ImMessageRecord{}
//把消息 写入通道
broadcast <- m
c.EnableRender = false //Beego不启用渲染 c.EnableRender = false //Beego不启用渲染
var s model.ImMessageRecord var s model.ImMessageRecord
broadcast <- &s for {
go func() { //接收客户端的消息
for { err := ws.ReadJSON(&s)
//接收客户端的消息 if err != nil {
err := ws.ReadJSON(&s) globals.SugarLogger.Debugf("页面可能断开啦 ws.ReadJSON error: %v", err.Error())
if err != nil { delete(clients, ws) //删除map中的客户端
globals.SugarLogger.Debugf("页面可能断开啦 ws.ReadJSON error: %v", err.Error()) break //结束循环
delete(clients, ws) //删除map中的客户端 } else {
break //结束循环 //接受消息 业务逻辑
} else { broadcast <- &s
broadcast <- &s db := dao.GetDB()
//接受消息 业务逻辑 dao.WrapAddIDCULDEntity(&s, "")
db := dao.GetDB() dao.CreateEntity(db, &s)
dao.WrapAddIDCULDEntity(&s, "") // fmt.Println("接受到从页面上反馈回来的信息 ", utils.Format4Output(s, false))
dao.CreateEntity(db, &s)
// fmt.Println("接受到从页面上反馈回来的信息 ", utils.Format4Output(s, false))
}
} }
}() }
} }
func init() { func init() {