token

package
v0.0.0-...-e38dd13 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidToken = errors.New("token is invalid")
	ErrExpiredToken = errors.New("token has expired")
)

Functions

This section is empty.

Types

type JWTMaker

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

func (*JWTMaker) CreateToken

func (maker *JWTMaker) CreateToken(userInfo UserInfo, duration time.Duration) (string, error)

func (*JWTMaker) VerifyToken

func (maker *JWTMaker) VerifyToken(token string) (*Payload, error)

type Maker

type Maker interface {
	CreateToken(userInfo UserInfo, duration time.Duration) (string, error)
	VerifyToken(token string) (*Payload, error)
}

func NewJWTMaker

func NewJWTMaker(secretKey string) (Maker, error)

type Payload

type Payload struct {
	UserInfo
	IssuedAt  time.Time `json:"issuedAt"`
	ExpiredAt time.Time `json:"expiredAt"`
}

func NewPayload

func NewPayload(userInfo UserInfo, duration time.Duration) (*Payload, error)

func (*Payload) Valid

func (payload *Payload) Valid() error

type UserInfo

type UserInfo struct {
	Username string `json:"username"`
	UserId   int64  `json:"userId"`
}

Jump to

Keyboard shortcuts

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