session

package
v0.3.5-0...-95db35b Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// OneDayExpired .
	OneDayExpired = 24 * time.Hour
	// OneWeekExpired .
	OneWeekExpired = 7 * 24 * time.Hour
	// OneMonthExpired .
	OneMonthExpired = 30 * 24 * time.Hour
)

Functions

This section is empty.

Types

type DefaultToken

type DefaultToken struct {
	LastLoginIP   string `json:"last_login_ip"`
	UserID        int64  `json:"user_id"`
	Telephone     string `json:"telepone"`
	Nickname      string `json:"nickname"`
	RedisTokenKey string `json:"token_key"`
	ExpiredAt     int64  `json:"expired_at"` // 时间戳 ms
}

DefaultToken . claims for jwt

func (*DefaultToken) Expiration

func (s *DefaultToken) Expiration() time.Duration

Expiration .

func (*DefaultToken) MarshalBinary

func (s *DefaultToken) MarshalBinary() ([]byte, error)

MarshalBinary .

func (*DefaultToken) SetExpiration

func (s *DefaultToken) SetExpiration(d time.Duration)

SetExpiration to update DefaultToken.ExpiredAt timestamp

func (*DefaultToken) TokenKey

func (s *DefaultToken) TokenKey() string

TokenKey .

func (*DefaultToken) UnmarshalBinary

func (s *DefaultToken) UnmarshalBinary(data []byte) error

UnmarshalBinary .

func (*DefaultToken) Valid

func (s *DefaultToken) Valid() error

Valid for session .

type IToken

type IToken interface {
	// functions for redis encoding and decoding
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler

	// following methods is provided to ITokenManager to op with token
	// TokenKey got key in redis or somewhere to find the token
	TokenKey() string
	// Expiration got time.Duration(int64) of token will expire at
	Expiration() time.Duration
	// Valid will raise error related to the method how to validate the information contained by token
	Valid() error
	// SetExpiration to update token expired time
	SetExpiration(d time.Duration)
}

IToken . an interface which contains necessary information of user who has logined to web application 支持多平台

func NewDefaultToken

func NewDefaultToken(uid int64, tel, nickname, ip string, d time.Duration) IToken

NewDefaultToken .

type ITokenManager

type ITokenManager interface {
	Set(tok IToken) error
	Exists(tok IToken) bool
	Expire(tok IToken) error
	Refresh(tok IToken, d time.Duration) error
	Get(key string, tok IToken) error
	PraseToken(token string, tok IToken) error
	Token(tok IToken) (string, error)
}

ITokenManager . 1. 能生成sessionkey 和 session 内容 2. 并发安全 3. 支持多平台token不冲突

func NewJwtTokenManager

func NewJwtTokenManager(rc *redis.Client, signedKey string) ITokenManager

NewJwtTokenManager .

Jump to

Keyboard shortcuts

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