session

package
v7.0.0-...-807de66 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package session SESSION 管理

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrSessionIDNotExists

func ErrSessionIDNotExists() error

func SecurityScheme

func SecurityScheme[T any](s *Session[T], id string, desc web.LocaleStringer) *openapi.SecurityScheme

SecurityScheme 声明支持 openapi 的 openapi.SecurityScheme 对象

Types

type Session

type Session[T any] struct {
	// contains filtered or unexported fields
}

Session session 管理

func New

func New[T any](s web.Server, store Store[T], lifetime int, name, path, domain string, secure, httpOnly bool) *Session[T]

New 声明 Session 中间件

lifetime 为 session 的有效时间,单位为秒;其它参数为 cookie 的相关设置。

func (*Session[T]) Delete

func (s *Session[T]) Delete(sessionid string) error

Delete 删除 session id

func (*Session[T]) GetInfo

func (s *Session[T]) GetInfo(ctx *web.Context) (T, bool)

func (*Session[T]) GetSessionID

func (s *Session[T]) GetSessionID(ctx *web.Context) (string, error)

func (*Session[T]) Logout

func (s *Session[T]) Logout(ctx *web.Context) error

Logout 退出登录

func (*Session[T]) Middleware

func (s *Session[T]) Middleware(next web.HandlerFunc, _, _, _ string) web.HandlerFunc

func (*Session[T]) Save

func (s *Session[T]) Save(ctx *web.Context, val T) error

Save 保存 val

func (*Session[T]) SecurityScheme

func (s *Session[T]) SecurityScheme(id string, desc web.LocaleStringer) *openapi.SecurityScheme

type Store

type Store[T any] interface {
	// Delete 删除指定 id 的 session
	Delete(id string) error

	// Get 查找指定 id 的 session
	//
	// bool 表示是否找到了该值;
	Get(id string) (T, bool, error)

	// Set 更新指定 id 的 session
	Set(id string, v T) error
}

Store session 的存储接口

func NewCacheStore

func NewCacheStore[T any](c web.Cache, ttl time.Duration) Store[T]

NewCacheStore 以 web.Cache 作为 session 的存储系统

Jump to

Keyboard shortcuts

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