2019-11-12 16:18:58 +08:00
|
|
|
package util
|
2019-11-11 19:13:17 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-contrib/sessions"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SetSession 设置session
|
|
|
|
func SetSession(c *gin.Context, list map[string]interface{}) {
|
|
|
|
s := sessions.Default(c)
|
|
|
|
for key, value := range list {
|
|
|
|
s.Set(key, value)
|
|
|
|
}
|
|
|
|
s.Save()
|
|
|
|
}
|
|
|
|
|
2019-11-13 17:03:55 +08:00
|
|
|
// GetSession 获取session
|
|
|
|
func GetSession(c *gin.Context, key string) interface{} {
|
|
|
|
s := sessions.Default(c)
|
|
|
|
return s.Get(key)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteSession 删除session
|
|
|
|
func DeleteSession(c *gin.Context, key string) {
|
|
|
|
s := sessions.Default(c)
|
|
|
|
s.Delete(key)
|
|
|
|
s.Save()
|
|
|
|
}
|
|
|
|
|
2019-11-11 19:13:17 +08:00
|
|
|
// ClearSession 清空session
|
|
|
|
func ClearSession(c *gin.Context) {
|
|
|
|
s := sessions.Default(c)
|
|
|
|
s.Clear()
|
|
|
|
s.Save()
|
|
|
|
}
|