token

package
v0.0.0-...-86e0aa6 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TOKEN_COOKIE_NAME  = "access_token"
	TOKEN_GIN_KEY_NAME = "access_token"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type LoginOutRequst

type LoginOutRequst struct {
	AccessToken string `json:"access_token"` //颁发给用户的访问令牌(需要用户携带token来访问接口)

}

万一的Token滋露,不知道refresh_token,也没法推出

func NewLoginOutRequst

func NewLoginOutRequst() *LoginOutRequst

让api调用使用的

type LoginRequst

type LoginRequst struct {
	Username string `form:"username" json:"username"`
	Password string `form:"password" json:"password"`
}

func NewLoginRequst

func NewLoginRequst() *LoginRequst

让api调用使用的

type Service

type Service interface {
	Login(context.Context, *LoginRequst) (*Token, error)               //登灵接口(额发Token)
	Logout(context.Context, *LoginOutRequst) error                     //登灵接口(销毁Token)
	ValiateToken(context.Context, *ValiateTokenRequst) (*Token, error) //校验Token 是给內部中间层使用 身份校验层
}

type Token

type Token struct {
	UserID                int64  `json:"user_id" gorm:"column:user_id"`                                   //该token是颁发给谁的
	UserName              string `json:"username" gorm:"column:username"`                                 //人的名字
	AccessToken           string `json:"access_token" gorm:"column:access_token"`                         //颁发给用户的访问令牌(需要用户携带token来访问接口)
	AccessTokenExpiredAt  int    `json:"access_token_expired_at" gorm:"column:access_token_expired_at"`   //过期时间
	RefreshToken          string `json:"refresh_token" gorm:"column:refresh_token"`                       //刷新令牌
	RefreshTokenExpiredAt int    `json:"refresh_token_expired_at" gorm:"column:refresh_token_expired_at"` //刷新令牌过期时间
	CreatedAt             int64  `json:"created_at" gorm:"column:created_at"`                             //创建时间
	UpdatedAt             int64  `json:"updated_at" gorm:"column:updated_at"`                             //刷新时间
	// AccessTokens          string `json:"access_tokens"`                   //颁发给用户的访问令牌(需要用户携带token来访问接口)
	Role                            user.Roles `gorm:"-"` // 额外补充信息, gorm忽略处理,这样就不需要存在数据库中了
	Access_token_expired_at_seconds string     `gorm:"-"` // 额外补充信息, gorm忽略处理,这样就不需要存在数据库中了
}

func NewToken

func NewToken() *Token

func (*Token) ExpiredTime

func (t *Token) ExpiredTime() time.Time

计算token的过期时间

func (*Token) IsExpired

func (t *Token) IsExpired() (string, error)

判断是否过期

func (*Token) String

func (u *Token) String() string

如果你想将 Token 结构体用于调试或记录日志,可以直接调用 String() 方法,得到一个包含了结构体内容的 JSON 字符串。

func (*Token) TableName

func (u *Token) TableName() string

可以指定该结构体在数据库中对应的表名

type ValiateTokenRequst

type ValiateTokenRequst struct {
	AccessToken string `json:"access_token"`
}

func NewValiateTokenRequst

func NewValiateTokenRequst(access_token_web string) *ValiateTokenRequst

让api调用使用的

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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