session

package
v0.0.0-...-8e4b865 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	Inject(id string, writer http.ResponseWriter) error // 幂等操作, 将session id注入
	Extract(req *http.Request) (string, error)          // 将session id 从http.Request 进行提取
	Delete(writer http.ResponseWriter) error            // 将 session id从 http.ResponseWriter 中移除
}

Adapter 适配层,不同的实现允许将 session id 存储在不同的地方

type Manager

type Manager struct {
	Store
	Adapter
	CtxKey string
}

func (*Manager) DeleteSession

func (m *Manager) DeleteSession(ctx *mserver.Context) error

func (*Manager) GetSession

func (m *Manager) GetSession(ctx *mserver.Context) (Session, error)

GetSession 从 ctx 中拿到 Session

func (*Manager) InitSession

func (m *Manager) InitSession(ctx *mserver.Context, id string) (Session, error)

InitSession 初始化session并注入到http中

func (*Manager) UpdateSession

func (m *Manager) UpdateSession(ctx *mserver.Context) (Session, error)

UpdateSession 更新session

type Session

type Session interface {
	Get(ctx context.Context, key string) (string, error)
	Set(ctx context.Context, key string, val string) error
	ID() string
}

Session 存储和查找用户设置的数据

type Store

type Store interface {
	Create(ctx context.Context, id string) (Session, error) // 创建session
	Update(ctx context.Context, id string) error            // 刷新session
	Delete(ctx context.Context, id string) error            // 删除session
	Get(ctx context.Context, id string) (Session, error)    // 查找session
}

Store 管理session的存储

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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