session

package
v0.0.0-...-75e85f9 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	Store
	Propagator
	// sessionId
	CtxSessKey string
}

func (*Manager) GetSession

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

func (*Manager) InitSession

func (m *Manager) InitSession(ctx *web.Context) (Session, error)

func (*Manager) RefreshSession

func (m *Manager) RefreshSession(ctx *web.Context) error

func (*Manager) RemoveSession

func (m *Manager) RemoveSession(ctx *web.Context) error

type Propagator

type Propagator interface {
	// Inject 将 sessionId 注入响应
	Inject(id string, writer http.ResponseWriter) error
	// Extract 从请求中提取 sessionId
	Extract(req *http.Request) (string, error)
	// Remove 移除 session
	Remove(writer http.ResponseWriter) error
}

Propagator 直接与 http 框架耦合

type Session

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

Session session 本身

type Store

type Store interface {
	// Generate
	// session 对应的 ID 谁来指定?
	// 要不要在接口维度上设置超时时间,以及,要不要让 Store 内部去生成ID,都是可以自由决策
	Generate(ctx context.Context, id string) (Session, error)
	// Refresh 刷新 session
	Refresh(ctx context.Context, id string) error
	// Remove 移除 session
	Remove(ctx context.Context, id string) error
	// Get 获取 session
	Get(ctx context.Context, id string) (Session, error)
}

Store 管理 Session 本身

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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