utils

package
v0.0.0-...-f791479 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

func Decode

func Decode(source, dest interface{}) error

func GenerateToken

func GenerateToken(email, password string) (string, error)

GenerateToken generates a jwt token and assign a email to it's claims and return it

func GetSecretKey

func GetSecretKey() []byte

func GetSnowflakeID

func GetSnowflakeID() string

func HashPassword

func HashPassword(password string) (string, error)

func InitSnowflakeGenerator

func InitSnowflakeGenerator(id int64) error

func ParseSnowflakeID

func ParseSnowflakeID(data string) (snowflake.ID, error)

func ParseToken

func ParseToken(tokenStr string) (string, error)

ParseToken parses a jwt token and returns the email in it's claims

func RefreshToken

func RefreshToken(tokenStr string, expirationTime time.Time) (string, error)

Types

type Claims

type Claims struct {
	Email    string `json:"email"`
	Password string `json:"password"`
	jwt.StandardClaims
}

Create a struct that will be encoded to a JWT. We add jwt.StandardClaims as an embedded type, to provide fields like expiry time

type Credentials

type Credentials struct {
	Password string `json:"password" mapstructure:"password"`
	Email    string `json:"email" mapstructure:"email"`
}

Create a struct to read the username and password from the request body

Jump to

Keyboard shortcuts

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