func roomGET(c *gin.Context) { roomid := c.Param("roomid") userid := fmt.Sprint(rand.Int31()) c.HTML(200, "chat_room", gin.H{ "roomid": roomid, "userid": userid, }) }
func roomPOST(c *gin.Context) { roomid := c.Param("roomid") userid := c.PostForm("user") message := c.PostForm("message") room(roomid).Submit(userid + ": " + message) c.JSON(200, gin.H{ "status": "success", "message": message, }) }
func stream(c *gin.Context) { roomid := c.Param("roomid") listener := openListener(roomid) defer closeListener(roomid, listener) c.Stream(func(w io.Writer) bool { c.SSEvent("message", <-listener) return true }) }
func roomDELETE(c *gin.Context) { roomid := c.Param("roomid") deleteBroadcast(roomid) }