session

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSessionExpired 表示会话已经过期
	ErrSessionExpired = errors.New("会话已过期")
)

Functions

This section is empty.

Types

type AesStorage

type AesStorage struct {
	// contains filtered or unexported fields
}

AesStorage 是用aes加密用户信息的方式做会话存储的一种实现

func NewAesStorage

func NewAesStorage(saes *util.SimpleAES) *AesStorage

NewAesStorage 构造AesStorage

func (*AesStorage) Del

func (s *AesStorage) Del(key string) error

Del 实现Storage

func (*AesStorage) Get

func (s *AesStorage) Get(key string, session interface{}) error

Get 实现Storage

func (*AesStorage) RefreshTTL

func (s *AesStorage) RefreshTTL(key string, ttl time.Duration) error

RefreshTTL 实现Storage

func (*AesStorage) Set

func (s *AesStorage) Set(session interface{}, ttl time.Duration) (key string, err error)

Set 实现Storage

type MysqlStorage

type MysqlStorage struct {
	// contains filtered or unexported fields
}

MysqlStorage 是存储在mysql中的会话

func NewMysqlStorage

func NewMysqlStorage(db *gorm.DB) *MysqlStorage

NewMysqlStorage 构造MysqlStorage

func (*MysqlStorage) Del

func (s *MysqlStorage) Del(key string) error

Del 实现Storage

func (*MysqlStorage) Get

func (s *MysqlStorage) Get(key string, session interface{}) error

Get 实现Storage

func (*MysqlStorage) RefreshTTL

func (s *MysqlStorage) RefreshTTL(key string, ttl time.Duration) error

RefreshTTL 实现Storage

func (*MysqlStorage) Set

func (s *MysqlStorage) Set(session interface{}, ttl time.Duration) (key string, err error)

Set 实现Storage

type RedisStorage

type RedisStorage struct {
	// contains filtered or unexported fields
}

RedisStorage redis实现的Storage

func (*RedisStorage) Del

func (s *RedisStorage) Del(key string) error

Del 实现Storage

func (*RedisStorage) Get

func (s *RedisStorage) Get(key string, session interface{}) (err error)

Get 实现Storage

func (*RedisStorage) RefreshTTL

func (s *RedisStorage) RefreshTTL(key string, ttl time.Duration) error

RefreshTTL 实现Storage

func (*RedisStorage) Set

func (s *RedisStorage) Set(session interface{}, ttl time.Duration) (key string, err error)

Set 实现Storage

type Storage

type Storage interface {
	Get(key string, session interface{}) error                          // 获取会话
	Set(session interface{}, ttl time.Duration) (key string, err error) // 存储会话 ttl=0表示不会失效
	RefreshTTL(key string, ttl time.Duration) error                     // 刷新会话存活时间 在原来过期时间基础上增加ttl
	Del(key string) error                                               // 删除会话
}

Storage 是会话信息存储器

func NewRedisStorage

func NewRedisStorage(prefix string, client *redis.Client) Storage

NewRedisStorage 构造redis实现的Storage

type Token

type Token struct {
	ID        uint   `gorm:"primaryKey"`
	Token     string `gorm:"type:varchar(30);uniqueIndex"`
	Data      string `gorm:"type:varchar(255)"`
	Permenent bool
	ExpireAt  time.Time
	CreatedAt time.Time
}

Token 是mysql中存储session的表

Jump to

Keyboard shortcuts

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