token

package
v1.2.11 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Code generated by gowebx, DO AVOID EDIT.

Code generated by gowebx, DO AVOID EDIT.

Code generated by gowebx, DO AVOID EDIT.

Code generated by gowebx, DO AVOID EDIT.

Code generated by gowebx, DO AVOID EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddTokenInput

type AddTokenInput struct {
	UserID    string   `json:"user_id"`    // 用户标识
	Scope     string   `json:"scope"`      // 应用场景
	Hash      []byte   `json:"hash"`       // 发给客户端的令牌 SHA-256 加密
	ExpiredAt orm.Time `json:"expired_at"` // 过期时间
}

type Core

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

Core business domain

func NewCore

func NewCore(store Storer) Core

NewCore create business domain

func (Core) AddToken

func (c Core) AddToken(ctx context.Context, in *AddTokenInput) (*Token, error)

AddToken Insert into database

func (Core) DelAllForUser added in v1.2.8

func (c Core) DelAllForUser(ctx context.Context, scope, userID string) ([]string, error)

DelAllForUser 删除用户的所有 token

func (Core) DelExpired

func (c Core) DelExpired(ctx context.Context, before time.Time) ([]string, error)

DelExpired 删除过期的 token

func (Core) DelToken

func (c Core) DelToken(ctx context.Context, id int) (*Token, error)

DelToken Delete object

func (Core) DelayToken

func (c Core) DelayToken(ctx context.Context, token string, expire time.Time) error

DelayToken 延迟 token,短期内只会延迟一次,expire 过期时间应该大于 10 分钟

func (Core) DelayTokenNow

func (c Core) DelayTokenNow(ctx context.Context, token string, expire time.Time) error

DelayTokenNow 立即延迟 token 过期时间

func (Core) EditToken

func (c Core) EditToken(ctx context.Context, in *EditTokenInput, id int) (*Token, error)

EditToken Update object information

func (Core) Expire added in v1.2.8

func (c Core) Expire(ctx context.Context, scope string, userID string, reason string) ([]string, error)

Expire 主动过期

func (Core) FindTokens

func (c Core) FindTokens(ctx context.Context, in *FindTokenInput) ([]*Token, int64, error)

FindToken Paginated search

func (Core) GetToken

func (c Core) GetToken(ctx context.Context, id int) (*Token, error)

GetToken Query a single object

func (Core) Valid

func (c Core) Valid(ctx context.Context, token string) error

Valid 验证 token 是否过期

type EditTokenInput

type EditTokenInput struct {
	UserID    string   `json:"user_id"`    // 用户标识
	Scope     string   `json:"scope"`      // 应用场景
	Hash      []byte   `json:"hash"`       // 发给客户端的令牌 SHA-256 加密
	ExpiredAt orm.Time `json:"expired_at"` // 过期时间
}

type FindTokenInput

type FindTokenInput struct {
	web.PagerFilter
	UserID    string   `form:"user_id"`    // 用户标识
	Scope     string   `form:"scope"`      // 应用场景
	Hash      []byte   `form:"hash"`       // 发给客户端的令牌 SHA-256 加密
	ExpiredAt orm.Time `form:"expired_at"` // 过期时间
}

type Storer

type Storer interface {
	Token() TokenStorer
}

Storer data persistence

type Token

type Token struct {
	ID        int      `gorm:"primaryKey" json:"id"`
	UserID    string   `gorm:"column:user_id;notNull;default:'';comment:用户标识" json:"user_id"` // 用户标识
	Scope     string   `gorm:"column:scope;notNull;default:'';comment:应用场景" json:"scope"`     // 应用场景
	Hash      []byte   `gorm:"column:hash;notNull;comment:发给客户端的令牌 SHA-256 加密" json:"hash"`   // 发给客户端的令牌 SHA-256 加密
	CreatedAt orm.Time `gorm:"column:created_at;notNull;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt orm.Time `gorm:"column:updated_at;notNull;default:CURRENT_TIMESTAMP" json:"updated_at"`
	ExpiredAt orm.Time `gorm:"column:expired_at;notNull;default:CURRENT_TIMESTAMP;comment:过期时间" json:"expired_at"` // 过期时间
	Reason    string   `gorm:"column:reason;notNull;default:''" json:"reason"`                                     // 过期原因
}

Token domain model

func (*Token) CacheKey

func (t *Token) CacheKey() string

CacheKey 缓存主键,必须唯一 godddx 生成缓存代码时,依赖的主键

func (*Token) TableName

func (*Token) TableName() string

TableName database table name

type TokenStorer

type TokenStorer interface {
	Find(context.Context, *[]*Token, orm.Pager, ...orm.QueryOption) (int64, error)
	Get(context.Context, *Token, ...orm.QueryOption) error
	Add(context.Context, *Token) error
	Edit(context.Context, *Token, func(*Token), ...orm.QueryOption) error
	Del(context.Context, *Token, ...orm.QueryOption) error
	DelExpired(ctx context.Context, before time.Time) ([]string, error)
	DelAllForUser(ctx context.Context, scope, userID string) ([]string, error)
	// 主动过期的函数,记录过期的原因,对用户友好
	Expire(ctx context.Context, scope, userID, reason string) ([]string, error)
}

TokenStorer Instantiation interface

Directories

Path Synopsis
store
tokencache
Code generated by gowebx, DO AVOID EDIT.
Code generated by gowebx, DO AVOID EDIT.
tokendb
Code generated by gowebx, DO AVOID EDIT.
Code generated by gowebx, DO AVOID EDIT.
Code generated by gowebx, DO AVOID EDIT.
Code generated by gowebx, DO AVOID EDIT.

Jump to

Keyboard shortcuts

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