utils

package
v0.0.0-...-4fa15db Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NameRegex = `^[a-z0-9]+(?:[._-][a-z0-9]+)*$`
	KB        = 1024
	MB        = 1024 * KB
	GB        = 1024 * MB
	TB        = 1024 * GB
)
View Source
const (
	FakeTag = "0000000000"
)

Variables

View Source
var (
	MockRedis *miniredis.Miniredis
)

Functions

func BackoffRetry

func BackoffRetry(ctx context.Context, maxAttempts int, f func() error) error

BackoffRetry retries up to `maxAttempts` times, and the interval will grow exponentially

func CleanRedisMutex

func CleanRedisMutex(name string) error

func Contains

func Contains(sli []string, str string) bool

func DeleteObjectsInRedis

func DeleteObjectsInRedis(ctx context.Context, keys ...string) error

func EncryptPassword

func EncryptPassword(passwd string) (string, error)

func EnsureDir

func EnsureDir(d string) error

func GenRandomBigString

func GenRandomBigString(length int) (string, error)

GenRandomBigString 生成指定长度大写字母组成的随机字符串

func GenerateUniqueID

func GenerateUniqueID(input string) string

func GetBooleanQuery

func GetBooleanQuery(c *gin.Context, key string, dValue bool) bool

func GetExpiredTimeByPeriod

func GetExpiredTimeByPeriod(period string) (*time.Time, error)

func GetInternalIP

func GetInternalIP() (string, error)

func GetMaxTime

func GetMaxTime() time.Time

func GetObjFromRedis

func GetObjFromRedis(ctx context.Context, k string, obj any) error

func GetRedisConn

func GetRedisConn() *redis.Client

func GetUniqueSID

func GetUniqueSID() string

func GetUniqueStr

func GetUniqueStr() (string, error)

func Invoke

func Invoke(fn func() error) error

func IsDefaultTag

func IsDefaultTag(tag string) bool

func LockRedisKey

func LockRedisKey(ctx context.Context, key string, expiry time.Duration) (func(), error)

func NewRedisCient

func NewRedisCient(cfg *config.RedisConfig) (ans *redis.Client)

func NewRedisMutex

func NewRedisMutex(name string, expiry time.Duration) *redsync.Mutex

func NormalizeTag

func NormalizeTag(tag string, digest string) string

func RadomStringByPhone

func RadomStringByPhone(phone string) string

RadomStringByPhone 根据用户电话号码以及当前时间生成随机字符串,8位

func RandomString

func RandomString(length int) string

func RoundMoney

func RoundMoney(v float64) float64

RoundMoney 四舍五入,小数点2位

func SetObjToRedis

func SetObjToRedis(ctx context.Context, k string, obj any, expiration time.Duration) error

func SetupRedis

func SetupRedis(cfg *config.RedisConfig, t *testing.T)

func UUIDStr

func UUIDStr() (string, error)

func UUIDStrNew

func UUIDStrNew() (string, error)

UUIDStrNew 六位随机大写字母_毫秒字符串

func WithTimeout

func WithTimeout(ctx context.Context, timeout time.Duration, f func(ctx2 context.Context))

Types

type RetryTask

type RetryTask struct {
	Func        func() error
	MaxAttempts int
	// contains filtered or unexported fields
}

RetryTask .

func NewRetryTask

func NewRetryTask(ctx context.Context, maxAttempts int, f func() error) *RetryTask

NewRetryTask .

func (*RetryTask) Run

func (r *RetryTask) Run(ctx context.Context) error

Run start running retry task

func (*RetryTask) Stop

func (r *RetryTask) Stop(context.Context)

Stop stops running task

Directories

Path Synopsis
sh

Jump to

Keyboard shortcuts

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