token

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrToken   = errors.New("token invalid")
	ErrExpired = errors.New("token expired")
)

Functions

This section is empty.

Types

type Jwt

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

func (*Jwt) CreateToken

func (j *Jwt) CreateToken(param *PayloadRequest) (string, *Payload, error)

func (*Jwt) VerifyToken

func (j *Jwt) VerifyToken(token string) (*Payload, error)

type Maker

type Maker interface {
	CreateToken(param *PayloadRequest) (string, *Payload, error)
	VerifyToken(token string) (*Payload, error)
}

func NewJwt

func NewJwt(secretkey string) (Maker, error)

type Payload

type Payload struct {
	ID        uuid.UUID `json:"id"`
	Username  string    `json:"username"`
	AccountID int64     `json:"account_id"`
	IssuedAt  time.Time `json:"issued_at"`
	ExpiredAt time.Time `json:"expired_at"`
}

func Newpayload

func Newpayload(param *PayloadRequest) (*Payload, error)

func (*Payload) Valid

func (p *Payload) Valid() error

type PayloadRequest

type PayloadRequest struct {
	Username  string        `json:"username"`
	AccountID int64         `json:"account_id"`
	Duration  time.Duration `json:"duration"`
}

Jump to

Keyboard shortcuts

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