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.
cloudreve/middleware/session.go

24 lines
696 B

5 years ago
package middleware
import (
"github.com/HFO4/cloudreve/pkg/util"
5 years ago
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/memstore"
"github.com/gin-contrib/sessions/redis"
5 years ago
"github.com/gin-gonic/gin"
)
5 years ago
// Store session存储
var Store memstore.Store
5 years ago
// 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)
}
5 years ago
// 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)
5 years ago
}