meetandeat/controller/examples/incr.go

24 lines
369 B
Go
Raw Normal View History

2019-03-22 16:35:16 +01:00
package examples
import (
"net/http"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
)
func incr(c *gin.Context) {
session := sessions.Default(c)
var count int
v := session.Get("count")
if v == nil {
count = 0
} else {
count = v.(int)
count++
}
session.Set("count", count)
session.Save()
c.JSON(http.StatusOK, gin.H{"count": count})
}