utils

package
v0.0.0-...-3264219 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Reset   = "\033[0m"
	Red     = "\033[31m"
	Green   = "\033[32m"
	Yellow  = "\033[33m"
	Blue    = "\033[34m"
	Purple  = "\033[35m"
	SkyBlue = "\033[36m"
)

Variables

This section is empty.

Functions

func Assert

func Assert(guard bool, text string)

func ConvertToBytes

func ConvertToBytes(size float64, unit SizeUnit) (int64, error)

ConvertToBytes converts a size given in the specified unit to bytes.

func EscapeQuotes

func EscapeQuotes(s string) string

func GenerateRandomToken

func GenerateRandomToken(length int) (string, error)

GenerateRandomToken creates a random token of the specified length.

func GenerateRange

func GenerateRange(start, end int) []int

GenerateRange creates a range of numbers from start to end.

func GenerateSalt

func GenerateSalt(length int) (string, error)

GenerateSalt creates a random salt of the given length.

func GetFolderPath

func GetFolderPath(folderName string) string

func GetRandomIndex

func GetRandomIndex(min, max int) (int, error)

GetRandomIndex generates a random index between min and max.

func HashPassword

func HashPassword(data string, salt string, length int) (string, error)

HashPassword generates a hash for the given data using the provided salt.

func IsASCII

func IsASCII(s string) bool

func MsToDay

func MsToDay(ms int64) int64

MsToDay converts milliseconds to days.

func MsToHr

func MsToHr(ms int64) int64

MsToHr converts milliseconds to hours.

func MsToHuman

func MsToHuman(ms int64, maxUnit string) string

MsToHuman converts milliseconds to a human-readable string.

func MsToMin

func MsToMin(ms int64) int64

MsToMin converts milliseconds to minutes.

func MsToSec

func MsToSec(ms int64) int64

MsToSec converts milliseconds to seconds.

func NewRedisClient

func NewRedisClient(redisAddr string) *redis.Client

func Retryable

func Retryable(fn func() error, retries int, backoffType string, delay time.Duration) error

Retryable retries the provided function on failure with backoff.

func ShuffleNumbers

func ShuffleNumbers(numbers []int) ([]int, error)

ShuffleNumbers randomly shuffles a slice of numbers.

func Sleep

func Sleep(ms int64)

Sleep pauses the execution for the given number of milliseconds.

Types

type SizeUnit

type SizeUnit string
const (
	Bytes     SizeUnit = "bytes"
	Kilobytes SizeUnit = "kilobytes"
	Megabytes SizeUnit = "megabytes"
	Gigabytes SizeUnit = "gigabytes"
)

Jump to

Keyboard shortcuts

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