utils

package
v0.0.0-...-c55c97e Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTokenExpired     = errors.New("token is expired")
	ErrTokenNotValidYet = errors.New("token not active yet")
	ErrTokenMalformed   = errors.New("that's not even a token")
	ErrTokenInvalid     = errors.New("couldn't handle this token")
)

Functions

func BcryptCheck

func BcryptCheck(password, hash string) bool

func BcryptHash

func BcryptHash(password string) string

func ClearToken

func ClearToken(w http.ResponseWriter, r *http.Request)

func GetClaims

func GetClaims(r *http.Request) (*types.CustomClaims, error)

func GetToken

func GetToken(r *http.Request) string

func GetUserId

func GetUserId(r *http.Request) int64

func MD5V

func MD5V(str []byte, b ...byte) string

func ParseDuration

func ParseDuration(d string) (time.Duration, error)

func SetToken

func SetToken(w http.ResponseWriter, r *http.Request, token string, maxAge int)

Types

type JWT

type JWT struct {
	SecretKey []byte
	Expire    string
	Buffer    string
	Issuer    string
	Audience  string
}

func NewJwt

func NewJwt(secretKey []byte, expire string, buffer string, issuer string, audience string) *JWT

func (*JWT) CreateClaims

func (j *JWT) CreateClaims(baseClaims types.BaseClaims) types.CustomClaims

func (*JWT) GenerateToken

func (j *JWT) GenerateToken(claims *types.CustomClaims) (string, error)

func (*JWT) ParseToken

func (j *JWT) ParseToken(tokenString string) (*types.CustomClaims, error)

解析 token

Jump to

Keyboard shortcuts

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