util

package
v0.0.0-...-385b71e Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TokenInvalid = errors.New("invalid token")
	TokenExpired = errors.New("token is expired")
)
View Source
var Generator = &IDGenerator{}

Functions

func ContainsStr

func ContainsStr(arr []string, target string) bool

func GenerateTokens

func GenerateTokens(username string, userID int64) (string, string, error)

func IsExpire

func IsExpire(token string) bool

func ParseRawToken

func ParseRawToken(rawToken string) string

func RefreshToken

func RefreshToken(rawToken string) (string, error)

func WrapHandlerFunctions

func WrapHandlerFunctions(rawFuncs ...http.HandlerFunc) []gin.HandlerFunc

Types

type Claims

type Claims struct {
	Username  string `json:"username"`
	UserID    int64  `json:"userID"`
	IsRefresh bool   `json:"isRefresh"`
	jwt.StandardClaims
}

func ParseAccessToken

func ParseAccessToken(tokenStr string) (*Claims, error)

func ParseRefreshToken

func ParseRefreshToken(tokenStr string) (*Claims, error)

type IDGenerator

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

func (*IDGenerator) GenerateID

func (g *IDGenerator) GenerateID() int64

type ShutdownHook

type ShutdownHook interface {
	// WithSignals add more signals into hook
	WithSignals(signals ...syscall.Signal) ShutdownHook

	// Close register shutdown handles
	Close(funcs ...func())
}

Hook a graceful shutdown hook, default with signals of SIGINT and SIGTERM

func NewShutdownHook

func NewShutdownHook() ShutdownHook

NewHook create a Hook instance

type Validator

type Validator struct {
	Operation string
	// contains filtered or unexported fields
}

func NewValidator

func NewValidator(t *testing.T, operation string) *Validator

func (*Validator) CheckBoolValue

func (v *Validator) CheckBoolValue(key string, expect bool, got bool) *Validator

func (*Validator) CheckInt64Value

func (v *Validator) CheckInt64Value(key string, expect int64, got int64) *Validator

func (*Validator) CheckIntValue

func (v *Validator) CheckIntValue(key string, expect int, got int) *Validator

func (*Validator) CheckStringValue

func (v *Validator) CheckStringValue(key string, expect string, got string) *Validator

Jump to

Keyboard shortcuts

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