This commit is contained in:
苏尹岚
2020-08-20 11:48:05 +08:00
parent dcdd41feaa
commit 7e3bf01ec3

View File

@@ -134,7 +134,8 @@ func (c *EventController) TestWebsocket() {
c.EnableRender = false //Beego不启用渲染 c.EnableRender = false //Beego不启用渲染
var s *model.ImMessageRecord var s model.ImMessageRecord
go func() {
for { for {
//接收客户端的消息 //接收客户端的消息
err := ws.ReadJSON(&s) err := ws.ReadJSON(&s)
@@ -143,8 +144,7 @@ func (c *EventController) TestWebsocket() {
delete(clients, ws) //删除map中的客户端 delete(clients, ws) //删除map中的客户端
break //结束循环 break //结束循环
} else { } else {
//把消息 写入通道 broadcast <- &s
broadcast <- s
//接受消息 业务逻辑 //接受消息 业务逻辑
db := dao.GetDB() db := dao.GetDB()
dao.WrapAddIDCULDEntity(&s, "") dao.WrapAddIDCULDEntity(&s, "")
@@ -152,6 +152,7 @@ func (c *EventController) TestWebsocket() {
// fmt.Println("接受到从页面上反馈回来的信息 ", utils.Format4Output(s, false)) // fmt.Println("接受到从页面上反馈回来的信息 ", utils.Format4Output(s, false))
} }
} }
}()
} }
func init() { func init() {