Help us shape the future of Go! Take the 2026 Go Developer Survey

token

package
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: GPL-3.0 Imports: 5 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSecretLen = errors.New("密钥长度不正确")

Functions

This section is empty.

Types

type Maker

type Maker interface {
	// CreateToken 生成Token
	CreateToken(content []byte, expireDate time.Duration) (string, *Payload, error)
	// VerifyToken 解析Token
	VerifyToken(token string) (*Payload, error)
}

func NewPasetoMaker

func NewPasetoMaker(key []byte) (Maker, error)

type PasetoMaker

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

func (*PasetoMaker) CreateToken

func (p *PasetoMaker) CreateToken(content []byte, expireDate time.Duration) (string, *Payload, error)

func (*PasetoMaker) VerifyToken

func (p *PasetoMaker) VerifyToken(token string) (*Payload, error)

type Payload

type Payload struct {
	// 用于管理每个JWT
	ID      uuid.UUID
	Content []byte `json:"content"` // 可以是任意内容
	// 创建时间用于检验
	IssuedAt  time.Time `json:"issued-at"`
	ExpiredAt time.Time `json:"expired-at"`
}

func NewPayload

func NewPayload(content []byte, expireDate time.Duration) (*Payload, error)

Jump to

Keyboard shortcuts

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