utils

package
v0.0.0-...-7ec3620 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccessTokenExpiry  = 15 * time.Minute
	RefreshTokenExpiry = 7 * 24 * time.Hour // 7 days
)

Access and Refresh Token expiry durations

Variables

This section is empty.

Functions

func CheckAndCovertToDate

func CheckAndCovertToDate(dateStr string) (string, error)

func ConvertToDate

func ConvertToDate(dateStr string) (*date.Date, error)

Convert a string in "YYYY-MM-DD" format to *date.Date

func ConvertToDateTime

func ConvertToDateTime(t time.Time) *datetime.DateTime

func TimeMustParse

func TimeMustParse(layout string) time.Time

Types

type BcryptHasher

type BcryptHasher struct{}

func (BcryptHasher) Generate

func (h BcryptHasher) Generate(password []byte, cost int) ([]byte, error)

type CustomClaims

type CustomClaims struct {
	UserID int `json:"user_id"`
	jwt.RegisteredClaims
}

Custom Claims structure

type PasswordHasher

type PasswordHasher interface {
	Generate(password []byte, cost int) ([]byte, error)
}

func NewPasswordHasher

func NewPasswordHasher() PasswordHasher

type TokenHandler

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

func (TokenHandler) CheckToken

func (t TokenHandler) CheckToken(tokenString string) (*CustomClaims, error)

CheckToken validates the given token string

func (TokenHandler) CreateToken

func (t TokenHandler) CreateToken(userID int) (accessTokenReturn string, refreshTokenReturn string, err error)

CreateToken generates an access token and a refresh token for the given userID

type TokenHandlerIntf

type TokenHandlerIntf interface {
	CreateToken(userID int) (accessTokenReturn string, refreshTokenReturn string, err error)
	CheckToken(tokenString string) (*CustomClaims, error)
}

func NewTokenHandler

func NewTokenHandler(config config.Config) TokenHandlerIntf

Jump to

Keyboard shortcuts

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