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}) }