token

package
v0.0.0-...-a7b145a Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2022 License: BSD-2-Clause Imports: 5 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")
)
View Source
var ProviderSet = wire.NewSet(NewJWTMaker)

Functions

This section is empty.

Types

type JWTMaker

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

JWTMaker implements the Maker interface.

func (*JWTMaker) CreateToken

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

CreateToken create a new jwt token with userId and duration.

func (*JWTMaker) VerifyToken

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

VerifyToken verify token and return payload.

type Maker

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

Maker is a token maker.

func NewJWTMaker

func NewJWTMaker(secretKey string) (Maker, error)

NewJWTMaker creates a JWTMaker with secret key length = 32.

type Payload

type Payload struct {
	Username  string    `json:"username"`
	IssuedAt  time.Time `json:"issued_at"`
	ExpiredAt time.Time `json:"expired_at"`
}

Payload is Jwt payload.

func NewPayload

func NewPayload(username string, duration time.Duration) (*Payload, error)

NewPayload create a new token payload.

func (*Payload) Valid

func (payload *Payload) Valid() error

Valid validates the payload is or not valid.

Jump to

Keyboard shortcuts

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