blog_backend_api/vendor/github.com/tommy351/gin-sessions
18650180552 2a1c947808 添加vendor 2019-01-28 11:19:49 +08:00
..
LICENSE 添加vendor 2019-01-28 11:19:49 +08:00
README.md 添加vendor 2019-01-28 11:19:49 +08:00
cookie_store.go 添加vendor 2019-01-28 11:19:49 +08:00
middleware.go 添加vendor 2019-01-28 11:19:49 +08:00
sessions.go 添加vendor 2019-01-28 11:19:49 +08:00

README.md

gin-sessions

Build Status

Session middleware for Gin.

Installation

$ go get github.com/tommy351/gin-sessions

Usage

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

func main(){
    g := gin.New()
    store := sessions.NewCookieStore([]byte("secret123"))
    g.Use(sessions.Middleware("my_session", store))
    
    g.GET("/set", func(c *gin.Context){
        session := sessions.Get(c)
        session.Set("hello", "world")
        session.Save()
    })
    
    g.GET("/get", func(c *gin.Context){
        session := sessions.Get(c)
        session.Get("hello")
    })
}