utils

package
v0.0.0-...-a2f4fc9 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TokenExpired     = errors.New("token is expired")
	TokenNotValidYet = errors.New("token not active yet")
	TokenMalformed   = errors.New("that's not even a token")
	TokenInvalid     = errors.New("couldn't handle this token")
)

Functions

func AsyncMap

func AsyncMap[T1 any, T2 any](arr *[]T1, f func(T1) T2) *[]T2

func BcryptCheck

func BcryptCheck(password, hash string) bool

BcryptCheck 对比明文密码和数据库的哈希值

func BcryptHash

func BcryptHash(password string) string

BcryptHash 使用 bcrypt 对密码进行加密

func CheckError

func CheckError(err error)

func DateOfString

func DateOfString(date string) (time.Time, error)

func Filter

func Filter[T any](arr []T, fun func(T) bool) []T

func HttpGet

func HttpGet[T any, R any](uri string, headers map[string]string, params T, resp R) error

func HttpPost

func HttpPost[T any, R any](uri string, headers map[string]string, body T, resp R) error

func JSONToMap

func JSONToMap(content interface{}) []map[string]any

func JsonTimeFormat

func JsonTimeFormat(t JsonTime) string

func Map

func Map[T1 any, T2 any](arr *[]T1, f func(T1) T2) *[]T2

func PathExists

func PathExists(path string) (bool, error)

func StringToTime

func StringToTime(t string) (time.Time, error)

func TimeFormat

func TimeFormat(t time.Time) string

func TimeOfString

func TimeOfString(t string) (time.Time, error)

func Translator

func Translator(locale string) (err error)

func Validate

func Validate(val interface{})

Types

type BaseClaims

type BaseClaims struct {
	ID       int64
	Username string
}

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache[T any](size int) *Cache[T]

func (*Cache[T]) Get

func (c *Cache[T]) Get(key string) (T, error)

func (*Cache[T]) Set

func (c *Cache[T]) Set(key string, val T) error

type CustomClaims

type CustomClaims struct {
	BaseClaims
	BufferTime int64
	jwt.RegisteredClaims
}

type JWT

type JWT struct {
	SigningKey []byte
}

func NewJWT

func NewJWT() *JWT

func (*JWT) CreateClaims

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

func (*JWT) CreateToken

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

CreateToken 创建一个token

func (*JWT) CreateTokenByOldToken

func (j *JWT) CreateTokenByOldToken(oldToken string, claims CustomClaims) (string, error)

CreateTokenByOldToken 旧token 换新token 使用归并回源避免并发问题

func (*JWT) ParseToken

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

ParseToken 解析 token

type JsonTime

type JsonTime time.Time

JsonTime format json time field by myself

func (JsonTime) MarshalJSON

func (t JsonTime) MarshalJSON() ([]byte, error)

MarshalJSON on JsonTime format Time field with Y-m-d H:i:s

func (*JsonTime) Scan

func (t *JsonTime) Scan(v interface{}) error

Scan value of time.Time

func (*JsonTime) Time

func (t *JsonTime) Time() time.Time

func (*JsonTime) UnmarshalJSON

func (t *JsonTime) UnmarshalJSON(data []byte) (err error)

func (JsonTime) Value

func (t JsonTime) Value() (driver.Value, error)

Value insert timestamp into mysql need this function.

Jump to

Keyboard shortcuts

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