utils

package
v0.0.0-...-cd3b21c Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinCost     int = 4
	MaxCost     int = 34
	DefaultCost int = 10
)

Variables

View Source
var (
	ErrTokenExpired      = errors.New("token expired")
	ErrUserNotFound      = errors.New("user not found")
	ErrSecretKeyTooShort = errors.New("secret key too short")
	ErrInvalidToken      = errors.New("invalid token")
)

Functions

func CheckPasswordHash

func CheckPasswordHash(password string, hash string) bool

func HashPassword

func HashPassword(password string) (string, error)

Types

type JWT

type JWT interface {
	CreateToken(user *User, duration time.Duration) (*JWTPayload, error)
	VerifyToken(tokn string) (*JWTPayload, error)
}

func NewJWT

func NewJWT() (JWT, error)

type JWTPayload

type JWTPayload struct {
	ID        int       `json:"id"`
	Email     string    `json:"email"`
	ExpiresAt time.Time `json:"expires_at"`
	IssuedAt  time.Time `json:"issued_at"`
	Token     string    `json:"token"`
}

func (*JWTPayload) Valid

func (j *JWTPayload) Valid() error

type JWTToken

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

func (*JWTToken) CreateToken

func (j *JWTToken) CreateToken(user *User, duration time.Duration) (*JWTPayload, error)

func (*JWTToken) VerifyToken

func (j *JWTToken) VerifyToken(tokn string) (*JWTPayload, error)

type User

type User struct {
	ID    int    `json:"id"`
	Email string `json:"email"`
}

Jump to

Keyboard shortcuts

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