This repository has been archived on 2024-11-28. You can view files and clone it, but cannot push or open issues or pull requests.
Files
schisandra-cloud-album/core/session.go
landaiqing 0b22d9800c 🎨 update
2024-11-05 17:24:11 +08:00

34 lines
754 B
Go

package core
import (
"context"
"net/http"
"github.com/gorilla/sessions"
"github.com/rbcervilla/redisstore/v9"
"github.com/redis/go-redis/v9"
"schisandra-cloud-album/common/constant"
"schisandra-cloud-album/global"
)
func InitSession(client *redis.Client) {
store, err := redisstore.NewRedisStore(context.Background(), client)
if err != nil {
global.LOG.Fatal("failed to create redis store: ", err)
}
// Example changing configuration for sessions
store.KeyPrefix(constant.UserSessionRedisKey)
store.Options(sessions.Options{
Path: "/",
// Domain: global.CONFIG.System.Web,
MaxAge: 86400 * 7,
HttpOnly: true,
Secure: true,
Partitioned: true,
SameSite: http.SameSiteLaxMode,
})
global.Session = store
}