1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00
cowyo/vendor/github.com/gin-gonic/contrib/sessions
Zack Scholl e8a4d30139 Now vendored, with Bolt v1.2.0
Former-commit-id: 900e1a398fd82aa1cea4f319e89b8088dd81cf6c [formerly f172c22b12c49c0291e0d986dc4af94fcc91d192] [formerly 43c5da81442a5f0ca79a6eabb1dfdfbfb3f22680 [formerly 2694d0b183]]
Former-commit-id: fa39d6a984adc4ca8f8c82c5df145c336885a53f [formerly 94543f8081bc18b1a39daf8500cfa7e0b1ba7393]
Former-commit-id: 809aae62e28a3f99a01854f71fcd5a85f89d2972
2017-01-31 08:05:27 -05:00
..
cookie.go Now vendored, with Bolt v1.2.0 2017-01-31 08:05:27 -05:00
README.md Now vendored, with Bolt v1.2.0 2017-01-31 08:05:27 -05:00
redis.go Now vendored, with Bolt v1.2.0 2017-01-31 08:05:27 -05:00
sessions.go Now vendored, with Bolt v1.2.0 2017-01-31 08:05:27 -05:00

sessions

Gin middleware for session management with multi-backend support (currently cookie, Redis).

EOL-warning

This package has been abandoned on 2016-12-07. Please use gin-contrib/sessions instead.

Examples

package main

import (
  "github.com/gin-gonic/contrib/sessions"
  "github.com/gin-gonic/gin"
)

func main() {
  r := gin.Default()
  store := sessions.NewCookieStore([]byte("secret"))
  r.Use(sessions.Sessions("mysession", store))

  r.GET("/incr", func(c *gin.Context) {
    session := sessions.Default(c)  
    var count int
    v := session.Get("count")
    if v == nil {
      count = 0
    } else {
      count = v.(int)
      count += 1
    }
    session.Set("count", count)
    session.Save()
    c.JSON(200, gin.H{"count": count})
  })
  r.Run(":8000")
}

Redis

package main

import (
  "github.com/gin-gonic/contrib/sessions"
  "github.com/gin-gonic/gin"
)

func main() {
  r := gin.Default()
  store, _ := sessions.NewRedisStore(10, "tcp", "localhost:6379", "", []byte("secret"))
  r.Use(sessions.Sessions("session", store))

  r.GET("/incr", func(c *gin.Context) {
    session := sessions.Default(c)
    var count int
    v := session.Get("count")
    if v == nil {
      count = 0
    } else {
      count = v.(int)
      count += 1
    }
    session.Set("count", count)
    session.Save()
    c.JSON(200, gin.H{"count": count})
  })
  r.Run(":8000")
}