You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
786 B
41 lines
786 B
package util
|
|
|
|
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)
|
|
}
|
|
|
|
err := s.Save()
|
|
if err != nil {
|
|
Log().Warning("无法设置 Session 值:%s", err)
|
|
}
|
|
}
|
|
|
|
// GetSession 获取session
|
|
func GetSession(c *gin.Context, key string) interface{} {
|
|
s := sessions.Default(c)
|
|
Log().Debug("Key:%s Val:%s", key, s.Get(key))
|
|
return s.Get(key)
|
|
}
|
|
|
|
// DeleteSession 删除session
|
|
func DeleteSession(c *gin.Context, key string) {
|
|
s := sessions.Default(c)
|
|
s.Delete(key)
|
|
s.Save()
|
|
}
|
|
|
|
// ClearSession 清空session
|
|
func ClearSession(c *gin.Context) {
|
|
s := sessions.Default(c)
|
|
s.Clear()
|
|
s.Save()
|
|
}
|