util

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InfinityDate = time.Date(2100, time.January, 1, 12, 0, 0, 0, time.UTC)

InfinityDate Infinity date

View Source
var OutDate = time.Date(1970, time.January, 1, 12, 0, 0, 0, time.UTC)

OutDate Default date

Functions

func ArrayFromString

func ArrayFromString(values string, separator string) []string

ArrayFromString Create array of values from separated string

func ArrayToString

func ArrayToString(values []string, separator string) string

ArrayToString Create separated string from array values

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

CheckPasswordHash Check password hash

func Contains added in v1.1.0

func Contains[K comparable](a []K, x K) bool

Contains check value present in array

func DeleteEmptyStrings added in v1.1.0

func DeleteEmptyStrings(s []string) []string

DeleteEmptyStrings return string slice without empty strings

func FileExists added in v0.2.0

func FileExists(filename string) bool

FileExists Is file exists

func FormatDate

func FormatDate(date time.Time) string

FormatDate Format date to string

func GenerateETag added in v0.10.3

func GenerateETag(str string, weak bool) string

Generates an Etag for given string. Allows specifying whether to generate weak Etag or not as second parameter

func GetAvatar added in v0.2.0

func GetAvatar(name, login, email string, size int, palette []color.Color,
	random bool) []byte

GetAvatar return avatar png bytes

func GetErrorDescription added in v1.5.2

func GetErrorDescription(bodyBytes []byte) string

GetErrorDescription get error from body

func GetHash

func GetHash(data []byte) string

GetHash Return hash of string

func GetRemoteBytes added in v0.7.0

func GetRemoteBytes(url, username, password string, addHeaders map[string]string, body []byte) ([]byte, int, error)

GetRemoteBytes Get remote data with timeout

func GetRemoteFile added in v1.4.0

func GetRemoteFile(url, username, password string, addHeaders map[string]string, outPath string) error

GetRemoteFile Get remote data with big timeout and write to file

func GetRemoteSmallFile added in v0.15.0

func GetRemoteSmallFile(url, username, password string, addHeaders map[string]string, outPath string) (int, error)

GetRemoteSmallFile Get remote data with timeout and write to file

func GetUA added in v1.6.0

func GetUA() string

GetUA return user agent

func GetVersion added in v1.9.1

func GetVersion() string

GetVersion return library version

func HashPassword

func HashPassword(password string) (string, error)

HashPassword Create hash from password

func IsDirEmpty

func IsDirEmpty(name string) (bool, error)

IsDirEmpty Check if directory is empty

func IsDirectory added in v0.2.0

func IsDirectory(path string) (bool, error)

IsDirectory Is path directory

func IsZeroTime added in v0.10.3

func IsZeroTime(t time.Time) bool

IsZeroTime Check if time is not init

func PostRemoteBytes added in v0.9.0

func PostRemoteBytes(url, username, password string, addHeaders map[string]string, data interface{}) ([]byte, int, error)

PostRemoteBytes Post remote data with timeout

func PostRemoteForm added in v1.5.0

func PostRemoteForm(url, username, password string, addHeaders map[string]string, data url.Values) ([]byte, error)

PostRemoteForm Post remote form with timeout

func PostRemoteSmallFile added in v0.16.0

func PostRemoteSmallFile(url, username, password string, addHeaders map[string]string, filePath, dstFileName string) ([]byte, int, error)

PostRemoteSmallFile Post remote data with timeout

func PutRemoteBytes added in v0.9.0

func PutRemoteBytes(url, username, password string, addHeaders map[string]string, data interface{}) ([]byte, int, error)

PutRemoteBytes Put remote data with timeout

func QueryParameterFloat added in v1.7.0

func QueryParameterFloat(gc *gin.Context, name string, defaultVal float64) float64

QueryParameterFloat Return query parameter as Float or default value

func QueryParameterInt added in v0.3.0

func QueryParameterInt(gc *gin.Context, name string, defaultVal int) int

QueryParameterInt Return query parameter as Int or default value

func QueryParameterString added in v0.3.0

func QueryParameterString(gc *gin.Context, name, defaultVal string) string

QueryParameterString Return query parameter or default value

func RandomKey

func RandomKey(n int) (string, error)

RandomKey Generate random key

func RemoveItem

func RemoveItem(slice []string, index int) []string

RemoveItem Remove item from slice at index

func StringToDate

func StringToDate(date string, defaultVal time.Time) time.Time

StringToDate Convert string to date

Types

type LockCache added in v1.1.0

type LockCache[K comparable] struct {
	// contains filtered or unexported fields
}

LockCache lock cache with expire support

func (*LockCache[K]) Free added in v1.1.0

func (lc *LockCache[K]) Free()

Free free unused resources

func (*LockCache[K]) Get added in v1.1.0

func (lc *LockCache[K]) Get(key K) (m *LockMutex, ok bool)

Get get lock mutex

func (*LockCache[K]) Init added in v1.1.0

func (lc *LockCache[K]) Init()

Init init lock cache

func (*LockCache[K]) Lock added in v1.1.0

func (lc *LockCache[K]) Lock(key K, duration time.Duration)

Lock lock by key

func (*LockCache[K]) RLock added in v1.8.0

func (lc *LockCache[K]) RLock(key K, duration time.Duration)

Lock lock by key

func (*LockCache[K]) RUnlock added in v1.8.0

func (lc *LockCache[K]) RUnlock(key K)

RUnlock unlock read mutex by key

func (*LockCache[K]) Set added in v1.1.0

func (lc *LockCache[K]) Set(key K, m *LockMutex)

Set set lock mutex

func (*LockCache[K]) TryLock added in v1.1.0

func (lc *LockCache[K]) TryLock(key K, duration time.Duration) bool

TryLock try to lock by key

func (*LockCache[K]) TryRLock added in v1.8.0

func (lc *LockCache[K]) TryRLock(key K, duration time.Duration) bool

TryRLock try to rlock by key

func (*LockCache[K]) Unlock added in v1.1.0

func (lc *LockCache[K]) Unlock(key K)

Unlock unlock by key

type LockMutex added in v1.1.0

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

LockMutex lock mutex with expiration

Jump to

Keyboard shortcuts

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