Fixes example code

This commit is contained in:
Manu Mtz-Almeida 2015-05-26 12:15:43 +02:00
parent d209329891
commit 4797530476
2 changed files with 12 additions and 12 deletions

View File

@ -31,8 +31,8 @@ func index(c *gin.Context) {
} }
func roomGET(c *gin.Context) { func roomGET(c *gin.Context) {
roomid := c.ParamValue("roomid") roomid := c.Param("roomid")
nick := c.FormValue("nick") nick := c.Query("nick")
if len(nick) < 2 { if len(nick) < 2 {
nick = "" nick = ""
} }
@ -48,9 +48,9 @@ func roomGET(c *gin.Context) {
} }
func roomPOST(c *gin.Context) { func roomPOST(c *gin.Context) {
roomid := c.ParamValue("roomid") roomid := c.Param("roomid")
nick := c.FormValue("nick") nick := c.Query("nick")
message := c.PostFormValue("message") message := c.PostForm("message")
message = strings.TrimSpace(message) message = strings.TrimSpace(message)
validMessage := len(message) > 1 && len(message) < 200 validMessage := len(message) > 1 && len(message) < 200
@ -73,7 +73,7 @@ func roomPOST(c *gin.Context) {
} }
func streamRoom(c *gin.Context) { func streamRoom(c *gin.Context) {
roomid := c.ParamValue("roomid") roomid := c.Param("roomid")
listener := openListener(roomid) listener := openListener(roomid)
ticker := time.NewTicker(1 * time.Second) ticker := time.NewTicker(1 * time.Second)
users.Add("connected", 1) users.Add("connected", 1)

View File

@ -21,7 +21,7 @@ func main() {
} }
func stream(c *gin.Context) { func stream(c *gin.Context) {
roomid := c.ParamValue("roomid") roomid := c.Param("roomid")
listener := openListener(roomid) listener := openListener(roomid)
defer closeListener(roomid, listener) defer closeListener(roomid, listener)
@ -32,7 +32,7 @@ func stream(c *gin.Context) {
} }
func roomGET(c *gin.Context) { func roomGET(c *gin.Context) {
roomid := c.ParamValue("roomid") roomid := c.Param("roomid")
userid := fmt.Sprint(rand.Int31()) userid := fmt.Sprint(rand.Int31())
c.HTML(200, "chat_room", gin.H{ c.HTML(200, "chat_room", gin.H{
"roomid": roomid, "roomid": roomid,
@ -41,9 +41,9 @@ func roomGET(c *gin.Context) {
} }
func roomPOST(c *gin.Context) { func roomPOST(c *gin.Context) {
roomid := c.ParamValue("roomid") roomid := c.Param("roomid")
userid := c.PostFormValue("user") userid := c.PostForm("user")
message := c.PostFormValue("message") message := c.PostForm("message")
room(roomid).Submit(userid + ": " + message) room(roomid).Submit(userid + ": " + message)
c.JSON(200, gin.H{ c.JSON(200, gin.H{
@ -53,6 +53,6 @@ func roomPOST(c *gin.Context) {
} }
func roomDELETE(c *gin.Context) { func roomDELETE(c *gin.Context) {
roomid := c.ParamValue("roomid") roomid := c.Param("roomid")
deleteBroadcast(roomid) deleteBroadcast(roomid)
} }