Documentation ¶
Index ¶
- Constants
- func GetSessionData(ctx *gin.Context) (data map[string]interface{}, err error)
- func WithSessionRedis(name string, cfg Cfg) gin.HandlerFunc
- type Cfg
- type RedisClusterStore
- func (s *RedisClusterStore) Close() error
- func (s *RedisClusterStore) Get(r *http.Request, name string) (*sessions.Session, error)
- func (s *RedisClusterStore) New(r *http.Request, name string) (*sessions.Session, error)
- func (s *RedisClusterStore) Save(_ *http.Request, w http.ResponseWriter, session *sessions.Session) error
- func (s *RedisClusterStore) SetKeyPrefix(p string)
- func (s *RedisClusterStore) SetMaxAge(v int) (err error)
- func (s *RedisClusterStore) SetMaxLength(l int)
- type Session
Constants ¶
View Source
const ( DefaultStoreKeyPrefix = "tenant:" // store里存储数据时的key DefaultSessionSecret = "ACtjU8wiey54EXinxPZ5" // cookie加密密钥 )
session相关常量
Variables ¶
This section is empty.
Functions ¶
func GetSessionData ¶
func WithSessionRedis ¶
func WithSessionRedis(name string, cfg Cfg) gin.HandlerFunc
WithSessionRedis session中间件,主要目的是创建一个session对象,并放到context里
Types ¶
type Cfg ¶
type RedisClusterStore ¶
type RedisClusterStore struct { Pool *redis.ClusterClient Codecs []securecookie.Codec Options *sessions.Options // default configuration DefaultMaxAge int // default Redis TTL for a MaxAge == 0 session // contains filtered or unexported fields }
RedisClusterStore 自定义store结构体,用于实现gorilla store的相关方法 仿写自:https://github.com/boj/redistore/tree/v1.2
func NewRedisClusterStore ¶
func (*RedisClusterStore) Close ¶
func (s *RedisClusterStore) Close() error
func (*RedisClusterStore) Save ¶
func (s *RedisClusterStore) Save(_ *http.Request, w http.ResponseWriter, session *sessions.Session) error
func (*RedisClusterStore) SetKeyPrefix ¶
func (s *RedisClusterStore) SetKeyPrefix(p string)
func (*RedisClusterStore) SetMaxAge ¶
func (s *RedisClusterStore) SetMaxAge(v int) (err error)
func (*RedisClusterStore) SetMaxLength ¶
func (s *RedisClusterStore) SetMaxLength(l int)
type Session ¶
type Session interface { // ID of the session, generated by stores. It should not be used for user data. ID() string // Get returns the session value associated to the given key. Get(key interface{}) interface{} // Set sets the session value associated to the given key. Set(key interface{}, val interface{}) // Delete removes the session value associated to the given key. Delete(key interface{}) // Clear deletes all values in the session. Clear() // Save saves all sessions used during the current request. Save() error // SetMaxAge set max age. SetMaxAge(n int) }
Session 自定义一个session接口,实例化以后,被用户调用
Click to show internal directories.
Click to hide internal directories.