Cloudreve/middleware/session.go

24 lines
696 B
Go
Raw Normal View History

2019-11-11 06:13:17 -05:00
package middleware
import (
"github.com/HFO4/cloudreve/pkg/util"
2019-11-11 06:13:17 -05:00
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/memstore"
"github.com/gin-contrib/sessions/redis"
2019-11-11 06:13:17 -05:00
"github.com/gin-gonic/gin"
)
2019-11-12 02:34:54 -05:00
// Store session存储
var Store memstore.Store
2019-11-11 06:13:17 -05:00
// Session 初始化session
func Session(secret string) gin.HandlerFunc {
Store, err := redis.NewStore(10, "tcp", "127.0.0.1:6379", "52121225", []byte("secret"))
if err != nil {
util.Log().Panic("无法连接到Redis%s", err)
}
2019-11-12 02:34:54 -05:00
// Also set Secure: true if using SSL, you should though
Store.Options(sessions.Options{HttpOnly: true, MaxAge: 7 * 86400, Path: "/"})
return sessions.Sessions("cloudreve-session", Store)
2019-11-11 06:13:17 -05:00
}