token

package
v1.7.9 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Code generated by godddx, DO AVOID EDIT.

Code generated by godddx, DO AVOID EDIT.

Code generated by godddx, DO AVOID EDIT.

Code generated by godddx, DO AVOID EDIT.

Code generated by godddx, 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) CreateToken added in v1.7.0

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

Create Token Insert into database

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) DeleteAllForUser added in v1.7.0

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

DeleteAllForUser 删除用户的所有 token

func (Core) DeleteExpired added in v1.7.0

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

DeleteExpired 删除过期的 token

func (Core) DeleteToken added in v1.7.0

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

DeleteToken Delete object

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) GetToken

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

GetToken Query a single object

func (Core) ListTokens added in v1.7.0

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

FindToken Paginated search

func (Core) UpdateToken added in v1.7.0

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

UpdateToken Update object information

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 {
	List(context.Context, *[]*Token, orm.Pager, ...orm.QueryOption) (int64, error)
	Get(context.Context, *Token, ...orm.QueryOption) error
	Create(context.Context, *Token) error
	Update(context.Context, *Token, func(*Token), ...orm.QueryOption) error
	Delete(context.Context, *Token, ...orm.QueryOption) error
	DeleteExpired(ctx context.Context, before time.Time) ([]string, error)
	DeleteAllForUser(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 godddx, DO AVOID EDIT.
Code generated by godddx, DO AVOID EDIT.
tokendb
Code generated by godddx, DO AVOID EDIT.
Code generated by godddx, DO AVOID EDIT.
Code generated by godddx, DO AVOID EDIT.
Code generated by godddx, DO AVOID EDIT.

Jump to

Keyboard shortcuts

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