sessionstore

package module
v0.0.0-...-9276fa0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2022 License: MIT Imports: 11 Imported by: 2

README

sessionstore

中文

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(b []byte) string

BytesToString converts byte slice to string.

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes converts string to byte slice.

Types

type Coder

type Coder interface {
	Unmarshal(b []byte) (session interface{}, e error)
	Marshal(session interface{}) (b []byte, e error)
}

type Manager

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

func New

func New(coder Coder, opt ...Option) (m *Manager)

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, access string) (e error)

刪除 token

func (*Manager) DeleteID

func (m *Manager) DeleteID(ctx context.Context, id string) (e error)

刪除指定 用戶 id 的所有 session

func (*Manager) DeletePlatform

func (m *Manager) DeletePlatform(ctx context.Context, id, platform string) (e error)

刪除指定用戶 id 在 指定平臺 platform 的所有 session

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, access string) (token *Token, session interface{}, e error)

返回 token 關聯的 session 數據

func (*Manager) GetRaw

func (m *Manager) GetRaw(ctx context.Context, access string) (key string, token *Token, b []byte, e error)

返回 token 關聯的 後端原始數據

func (*Manager) NewToken

func (m *Manager) NewToken(prefix string) (token string, e error)

創建一個 token

func (*Manager) Put

func (m *Manager) Put(ctx context.Context, id, platform string, session interface{}) (token *Token, e error)

創建 session 關聯的 token

func (*Manager) Refresh

func (m *Manager) Refresh(ctx context.Context, access, refresh string) (token *Token, session interface{}, e error)

func (*Manager) Sin

func (m *Manager) Sin(playdata string) (token string, e error)

簽名數據

func (*Manager) Verify

func (m *Manager) Verify(token string) (playdata string, e error)

驗證簽名是否有效

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithAccess

func WithAccess(access time.Duration) Option

func WithDeadline

func WithDeadline(deadline time.Duration) Option

func WithKey

func WithKey(key []byte) Option

func WithMethod

func WithMethod(method cryptoer.SigningMethod) Option

func WithRefresh

func WithRefresh(refresh time.Duration) Option

func WithStore

func WithStore(store Store) Option

type Store

type Store interface {
	// 設置數據
	Put(ctx context.Context, key string, value []byte, deadline time.Time) (e error)
	// 返回數據
	Get(ctx context.Context, key string) (value []byte, e error)
	// 刪除數據
	Del(ctx context.Context, key string) (e error)
	// 刪除指定前綴的數據
	DelPrefix(ctx context.Context, prefix string) (e error)
	// 關閉存儲設備 釋放相關資源
	Close() (e error)
}

type Token

type Token struct {
	Access          string
	Refresh         string
	AccessDeadline  int64
	RefreshDeadline int64
	Deadline        int64
}

func NewToken

func NewToken(access, refresh string,
	accessDeadline, refreshDeadline int64,
	deadline int64) *Token

func (*Token) CanRefresh

func (t *Token) CanRefresh() bool

func (*Token) IsDeleted

func (t *Token) IsDeleted() bool

func (*Token) IsExpired

func (t *Token) IsExpired() bool

Directories

Path Synopsis
sessionstore

Jump to

Keyboard shortcuts

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