jwtApi

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PrefixBearer = "Bearer"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type JwtCfg

type JwtCfg struct {
	TokenExpireDuration time.Duration //默认为永不过期
	Issuer              string
	// contains filtered or unexported fields
}

func InitJwt

func InitJwt(key string, opts ...OptionFunc) *JwtCfg

InitJwt 初始化jwt管理器

func (*JwtCfg) ParseToken

func (j *JwtCfg) ParseToken(tokenStr string) (*MyClaims, error)

ParseToken 解析 jwt token

func (*JwtCfg) SignedTokenStr

func (j *JwtCfg) SignedTokenStr(data any) (string, error)

SignedTokenStr 签发jwt token

func (*JwtCfg) SignedTokenStrWithID

func (j *JwtCfg) SignedTokenStrWithID(data any, id string) (string, error)

SignedTokenStrWithID 签发jwt token with ID

type MyClaims

type MyClaims struct {
	Token any
	jwt.RegisteredClaims
}

func (*MyClaims) TokenObj

func (mc *MyClaims) TokenObj(obj any) error

obj 为指针,内部实现为json unmarshal

type OptionFunc

type OptionFunc func(cfg *JwtCfg)

func WithExp

func WithExp(exp time.Duration) OptionFunc

WithExp 过期时间

func WithIssuer

func WithIssuer(iss string) OptionFunc

WithIssuer 添加issuer 项目名称

Jump to

Keyboard shortcuts

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