package controller import ( "github.com/gin-gonic/gin" "kefu/types" "kefu/ws" ) //监控访客列表 func GetMonitorList(c *gin.Context) { kefuName, _ := c.Get("kefu_name") list := make([]*ws.MonitorConnection, 0) for _, connect := range ws.MonitorList { if connect.KefuName == kefuName { list = append(list, connect) } } c.JSON(200, gin.H{ "code": 200, "msg": "ok", "result": list, }) } type MonitorMessageForm struct { UniqId string `form:"uniqid" json:"uniqid" uri:"uniqid" xml:"uniqid" binding:"required"` Message string `form:"message" json:"message" uri:"message" xml:"message" binding:"required"` } //监控访客消息 func PostMonitorMessage(c *gin.Context) { var form MonitorMessageForm err := c.Bind(&form) if err != nil { c.JSON(200, gin.H{ "code": types.ApiCode.FAILED, "msg": types.ApiCode.GetMessage(types.ApiCode.INVALID), "result": err.Error(), }) return } kefuName, _ := c.Get("kefu_name") for conn, connect := range ws.MonitorList { if connect.KefuName == kefuName && form.UniqId == connect.UinqId { conn.WriteMessage(1, []byte(form.Message)) } } c.JSON(200, gin.H{ "code": 200, "msg": "ok", }) }