common

package
v0.0.0-...-04312dd Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KB int64 = 1 << (10 * iota)
	MB
	GB
	TB
)
View Source
const (
	GinContextTransaction   = "umc-gin-transaction"
	GinUseGlobalTransaction = "umc-gin-global-transaction"
)

Variables

View Source
var (
	TokenTimeout   = errors.New("Token is timeout")
	TokenNotActive = errors.New("Token not active")
	TokenInvalid   = errors.New("Token invalid")
)

Functions

func FileExist

func FileExist(path string) bool

func GetContextValue

func GetContextValue[T any](ctx context.Context, key string) *T

func GetGinTransaction

func GetGinTransaction()

func GetVarP

func GetVarP[T any](t T) *T

func IntSliceToString

func IntSliceToString(ints []int) string

func MD5

func MD5(str string) string

func RandToken

func RandToken(num int) string

Types

type BaseClaims

type BaseClaims struct {
	UserID   uint
	Account  string
	UUID     string
	ClientId string
}

type CustomClaims

type CustomClaims struct {
	BaseClaims
	BufferTime time.Time
	jwt.RegisteredClaims
}

type JWT

type JWT struct {
	Issuer     string
	Key        []byte
	Timeout    time.Duration
	BufferTime time.Duration
}

func NewJWT

func NewJWT(key string, timeout int, Issuer string, bufferTime int) *JWT

func (*JWT) CreateClaims

func (j *JWT) CreateClaims(base BaseClaims) CustomClaims

func (*JWT) CreateToken

func (j *JWT) CreateToken(claims *CustomClaims) (string, error)

func (*JWT) ParseToken

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

func (*JWT) ReCreateToken

func (j *JWT) ReCreateToken(old string, claims *CustomClaims) (string, error)

Jump to

Keyboard shortcuts

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