utils

package
v0.0.0-...-c0c742b Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESGCMDecrypt

func AESGCMDecrypt(key []byte, ciphertext []byte) ([]byte, error)

AESGCMDecrypt returns a decrypted string by aes-gcm

func AESGCMEncrypt

func AESGCMEncrypt(key []byte, plainText []byte) ([]byte, error)

AESGCMEncrypt returns a encrypted string by aes-gcm

func Clone

func Clone(src, dst any) error

Clone deep-clones src object to dst object

func DecryptSecret

func DecryptSecret(encyptedSecret string, key string) (string, error)

DecryptSecret returns a decrypted secret

func EncodePassword

func EncodePassword(password string, salt string) string

EncodePassword returns a encoded password

func EncryptSecret

func EncryptSecret(secret string, key string) (string, error)

EncryptSecret returns a encrypted secret

func Float64ToString

func Float64ToString(num float64) string

Float64ToString returns the textual representation of this number

func FormatTimezoneOffset

func FormatTimezoneOffset(timezone *time.Location) string

FormatTimezoneOffset returns "+/-HH:MM" format of timezone

func FormatUnixTimeToLongDateTimeInServerTimezone

func FormatUnixTimeToLongDateTimeInServerTimezone(unixTime int64) string

FormatUnixTimeToLongDateTimeInServerTimezone returns a textual representation of the unix time formatted by long date time format

func FormatUnixTimeToLongDateTimeWithoutSecond

func FormatUnixTimeToLongDateTimeWithoutSecond(unixTime int64, timezone *time.Location) string

FormatUnixTimeToLongDateTimeWithoutSecond returns a textual representation of the unix time formatted by long date time format (no second)

func FormatUnixTimeToYearMonth

func FormatUnixTimeToYearMonth(unixTime int64, timezone *time.Location) string

FormatUnixTimeToYearMonth returns year and month of specified unix time

func GetFirstLowerCharString

func GetFirstLowerCharString(s string) string

GetFirstLowerCharString returns the source string parameter, but makes the first character lower case

func GetGravatarUrl

func GetGravatarUrl(email string) string

GetGravatarUrl returns the Gravatar url according to the specified user email address

func GetLocalIPAddresses

func GetLocalIPAddresses() ([]net.IP, error)

GetLocalIPAddresses returns all local ip address object array

func GetLocalIPAddressesString

func GetLocalIPAddressesString() (string, error)

GetLocalIPAddressesString returns all local ip address, every ip split by comma

func GetMaxTransactionTimeFromUnixTime

func GetMaxTransactionTimeFromUnixTime(unixTime int64) int64

GetMaxTransactionTimeFromUnixTime returns the maximum transaction time from unix time

func GetMinTransactionTimeFromUnixTime

func GetMinTransactionTimeFromUnixTime(unixTime int64) int64

GetMinTransactionTimeFromUnixTime returns the minimum transaction time from unix time

func GetRandomInteger

func GetRandomInteger(max int) (int, error)

GetRandomInteger returns a random number, the max parameter represents upper limit

func GetRandomNumberOrLetter

func GetRandomNumberOrLetter(n int) (string, error)

GetRandomNumberOrLetter returns a random string which only contains number or letter characters

func GetRandomNumberOrLowercaseLetter

func GetRandomNumberOrLowercaseLetter(n int) (string, error)

GetRandomNumberOrLowercaseLetter returns a random string which only contains number or letter characters

func GetRandomString

func GetRandomString(n int) (string, error)

GetRandomString returns a random string of which length is n

func GetTimezoneOffsetMinutes

func GetTimezoneOffsetMinutes(timezone *time.Location) int16

GetTimezoneOffsetMinutes returns offset minutes according specified timezone

func GetUnixTimeFromTransactionTime

func GetUnixTimeFromTransactionTime(transactionTime int64) int64

GetUnixTimeFromTransactionTime returns unix time from the transaction time

func IdentReader

func IdentReader(encoding string, input io.Reader) (io.Reader, error)

IdentReader returns the original io reader

func Int64ArrayToStringArray

func Int64ArrayToStringArray(num []int64) []string

Int64ArrayToStringArray returns a array of textual representation of these numbers

func Int64SliceEquals

func Int64SliceEquals(s1, s2 []int64) bool

Int64SliceEquals returns whether specific two int64 arrays equal

func Int64SliceMinus

func Int64SliceMinus(s1, s2 []int64) []int64

Int64SliceMinus returns a int64 array which contains items in s1 but not in s2

func Int64ToString

func Int64ToString(num int64) string

Int64ToString returns the textual representation of this number

func IntToString

func IntToString(num int) string

IntToString returns the textual representation of this number

func IsExists

func IsExists(path string) (bool, error)

IsExists returns whether specified file or directory path exits

func IsUnixTimeEqualsYearAndMonth

func IsUnixTimeEqualsYearAndMonth(unixTime int64, timezone *time.Location, year int32, month int32) bool

IsUnixTimeEqualsYearAndMonth returns whether year and month of the unix time are equals to the specified year and month

func IsValidEmail

func IsValidEmail(email string) bool

IsValidEmail reports whether email is valid

func IsValidHexRGBColor

func IsValidHexRGBColor(color string) bool

IsValidHexRGBColor reports whether color is valid

func IsValidUsername

func IsValidUsername(username string) bool

IsValidUsername reports whether username is valid

func ListFileNamesWithPrefixAndSuffix

func ListFileNamesWithPrefixAndSuffix(path string, prefix string, suffix string) []string

ListFileNamesWithPrefixAndSuffix returns file name list which has specified prefix and suffix

func MD5Encode

func MD5Encode(data []byte) []byte

MD5Encode returns a hashed string by md5

func MD5EncodeToString

func MD5EncodeToString(data []byte) string

MD5EncodeToString returns a hashed string by md5

func ParseFromElapsedSeconds

func ParseFromElapsedSeconds(elapsedSeconds int) (string, error)

func ParseFromLongDateTime

func ParseFromLongDateTime(t string, utcOffset int16) (time.Time, error)

ParseFromLongDateTime parses a formatted string in long date time format

func ParseFromLongDateTimeToMaxUnixTime

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

ParseFromLongDateTimeToMaxUnixTime parses a formatted string in long date time format to maximal unix time (the easternmost timezone)

func ParseFromLongDateTimeToMinUnixTime

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

ParseFromLongDateTimeToMinUnixTime parses a formatted string in long date time format to minimal unix time (the westernmost timezone)

func ParseFromLongDateTimeWithoutSecond

func ParseFromLongDateTimeWithoutSecond(t string, timezone *time.Location) (time.Time, error)

ParseFromLongDateTimeWithoutSecond parses a formatted string in long date time format (no second)

func ParseFromShortDateTime

func ParseFromShortDateTime(t string, utcOffset int16) (time.Time, error)

ParseFromShortDateTime parses a formatted string in short date time format

func ParseFromTimezoneOffset

func ParseFromTimezoneOffset(tzOffset string) (*time.Location, error)

ParseFromTimezoneOffset parses a formatted string in timezone offset format

func PrintDataErrorResult

func PrintDataErrorResult(c *core.Context, contentType string, err *errs.Error)

PrintDataErrorResult writes error response in custom content type to current http context

func PrintDataSuccessResult

func PrintDataSuccessResult(c *core.Context, contentType string, fileName string, result []byte)

PrintDataSuccessResult writes success response in custom content type to current http context

func PrintJsonErrorResult

func PrintJsonErrorResult(c *core.Context, err *errs.Error)

PrintJsonErrorResult writes error response in json format to current http context

func PrintJsonSuccessResult

func PrintJsonSuccessResult(c *core.Context, result any)

PrintJsonSuccessResult writes success response in json format to current http context

func PrintObjectFields

func PrintObjectFields(obj any)

PrintObjectFields prints all fields in specified object

func SetProxyUrl

func SetProxyUrl(transport *http.Transport, proxy string)

SetProxyUrl sets proxy url to http transport according to specified proxy setting

func StringArrayToInt64Array

func StringArrayToInt64Array(strs []string) ([]int64, error)

StringArrayToInt64Array parses a series textual representations of the numbers to int64 array

func StringToFloat64

func StringToFloat64(str string) (float64, error)

StringToFloat64 parses a textual representation of the number to float64

func StringToInt

func StringToInt(str string) (int, error)

StringToInt parses a textual representation of the number to int

func StringToInt32

func StringToInt32(str string) (int32, error)

StringToInt32 parses a textual representation of the number to int32

func StringToInt64

func StringToInt64(str string) (int64, error)

StringToInt64 parses a textual representation of the number to int64

func StringTryToInt

func StringTryToInt(str string, defaultValue int) int

StringTryToInt parses a textual representation of the number to int if str is valid, or returns the default value

func StringTryToInt64

func StringTryToInt64(str string, defaultValue int64) int64

StringTryToInt64 parses a textual representation of the number to int64 if str is valid, or returns the default value

func SubString

func SubString(str string, start int, length int) string

SubString returns part of the source string according to start index and length

func ToUniqueInt64Slice

func ToUniqueInt64Slice(items []int64) []int64

ToUniqueInt64Slice returns a int64 array which does not have duplicated items

func WriteFile

func WriteFile(path string, data []byte) error

WriteFile would write file according to specified content

Types

type CookieExtractor

type CookieExtractor []string

CookieExtractor extracts a token from request cookies

func (CookieExtractor) ExtractToken

func (e CookieExtractor) ExtractToken(req *http.Request) (string, error)

Jump to

Keyboard shortcuts

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