session

package
v0.0.0-...-6562851 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultStoreKeyPrefix = "tenant:"              // store里存储数据时的key
	DefaultSessionSecret  = "ACtjU8wiey54EXinxPZ5" // cookie加密密钥
)

session相关常量

Variables

This section is empty.

Functions

func GetSessionData

func GetSessionData(ctx *gin.Context) (data map[string]interface{}, err error)

func WithSessionRedis

func WithSessionRedis(name string, cfg Cfg) gin.HandlerFunc

WithSessionRedis session中间件,主要目的是创建一个session对象,并放到context里

Types

type Cfg

type Cfg struct {
	Public  string `json:"public" toml:"public"`
	Private string `json:"private" toml:"private"`
}

func NewCfg

func NewCfg(public string, private string) *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 NewRedisClusterStore(cfg Cfg, keyPrefix string, redisAge, maxLength int, secure, httpOnly bool, sameSiteMode http.SameSite, _ ...[]byte) (*RedisClusterStore, error)

func (*RedisClusterStore) Close

func (s *RedisClusterStore) Close() error

func (*RedisClusterStore) Get

func (s *RedisClusterStore) Get(r *http.Request, name string) (*sessions.Session, error)

func (*RedisClusterStore) New

func (s *RedisClusterStore) New(r *http.Request, name string) (*sessions.Session, error)

func (*RedisClusterStore) Save

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接口,实例化以后,被用户调用

func DefaultSession

func DefaultSession(c *gin.Context) Session

DefaultSession 获取session

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL