utils

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 29 Imported by: 32

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 ContainsAnyString added in v1.2.0

func ContainsAnyString(s string, substrs []string) bool

ContainsAnyString returns whether the specified string contains any string of sub string slice

func ContainsOnlyOneRune added in v0.6.0

func ContainsOnlyOneRune(s string, r rune) bool

ContainsOnlyOneRune returns the source string only contains one character

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 FormatAmount added in v0.6.0

func FormatAmount(value int64) string

FormatAmount returns a textual representation of amount

func FormatTimezoneOffset

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

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

func FormatTimezoneOffsetFromHoursOffset added in v0.6.0

func FormatTimezoneOffsetFromHoursOffset(hoursOffset string) (string, error)

FormatTimezoneOffsetFromHoursOffset returns "+/-HH:MM" format of timezone from hours offset

func FormatUnixTimeToLongDate added in v0.8.0

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

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

func FormatUnixTimeToLongDateTime added in v0.5.0

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

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

func FormatUnixTimeToLongDateTimeInServerTimezone

func FormatUnixTimeToLongDateTimeInServerTimezone(unixTime int64) string

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

func FormatUnixTimeToLongDateTimeWithTimezone added in v0.10.0

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

FormatUnixTimeToLongDateTimeWithTimezone returns a textual representation of the unix time formatted by long date time with timezone format

func FormatUnixTimeToLongDateTimeWithTimezoneRFC3339Format added in v0.10.0

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

FormatUnixTimeToLongDateTimeWithTimezoneRFC3339Format returns a textual representation of the unix time formatted by long date time with timezone RFC 3339 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 FormatUnixTimeToNumericLocalDateTime added in v0.5.0

func FormatUnixTimeToNumericLocalDateTime(unixTime int64, timezone *time.Location) int64

FormatUnixTimeToNumericLocalDateTime returns numeric year, month, day, hour, minute and second of specified unix time

func FormatUnixTimeToNumericYearMonth added in v0.5.0

func FormatUnixTimeToNumericYearMonth(unixTime int64, timezone *time.Location) int32

FormatUnixTimeToNumericYearMonth returns numeric year and month of specified unix time

func FormatUnixTimeToNumericYearMonthDay added in v1.2.0

func FormatUnixTimeToNumericYearMonthDay(unixTime int64, timezone *time.Location) int32

FormatUnixTimeToNumericYearMonthDay returns numeric year, month and day of specified unix time

func FormatUnixTimeToYearMonth

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

FormatUnixTimeToYearMonth returns year and month of specified unix time

func FormatYearMonthDayToLongDateTime added in v0.10.0

func FormatYearMonthDayToLongDateTime(year string, month string, day string) (string, error)

func GetDisplayErrorMessage added in v1.2.0

func GetDisplayErrorMessage(err *errs.Error) string

GetDisplayErrorMessage returns the display error message for given error

func GetFileNameExtension added in v0.5.0

func GetFileNameExtension(path string) string

GetFileNameExtension returns the file extension without dot

func GetFileNameWithoutExtension added in v0.5.0

func GetFileNameWithoutExtension(path string) string

GetFileNameWithoutExtension returns the file name without extension

func GetFirstLowerCharString

func GetFirstLowerCharString(s string) string

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

func GetImageContentType added in v0.5.0

func GetImageContentType(fileExtension string) string

GetImageContentType returns the content type of specified image file extension or returns empty when the file extension is not image or not supported

func GetJsonErrorResult added in v1.2.0

func GetJsonErrorResult(err *errs.Error, path string) map[string]any

GetJsonErrorResult returns error response in json format

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 GetMaxUnixTimeWithSameLocalDateTime added in v0.5.0

func GetMaxUnixTimeWithSameLocalDateTime(unixTime int64, currentUtcOffset int16) int64

GetMaxUnixTimeWithSameLocalDateTime returns the maximum UnixTime for date with the same local date

func GetMinTransactionTimeFromUnixTime

func GetMinTransactionTimeFromUnixTime(unixTime int64) int64

GetMinTransactionTimeFromUnixTime returns the minimum transaction time from unix time

func GetMinUnixTimeWithSameLocalDateTime added in v0.5.0

func GetMinUnixTimeWithSameLocalDateTime(unixTime int64, currentUtcOffset int16) int64

GetMinUnixTimeWithSameLocalDateTime returns the minimum UnixTime for date with the same local date

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 added in v0.2.0

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 GetServerTimezoneOffsetMinutes added in v0.5.0

func GetServerTimezoneOffsetMinutes() int16

GetServerTimezoneOffsetMinutes returns offset minutes of current server timezone

func GetStartOfDay added in v1.3.0

func GetStartOfDay(t time.Time) time.Time

GetStartOfDay returns the start time of the day for the specified time

func GetTimezoneOffsetMinutes

func GetTimezoneOffsetMinutes(unixTime int64, timezone *time.Location) int16

GetTimezoneOffsetMinutes returns offset minutes according specified timezone

func GetTransactionTimeRangeByYearMonth added in v0.5.0

func GetTransactionTimeRangeByYearMonth(year int32, month int32) (int64, int64, error)

GetTransactionTimeRangeByYearMonth returns the transaction time range by specified year and month

func GetUnixTimeFromTransactionTime

func GetUnixTimeFromTransactionTime(transactionTime int64) int64

GetUnixTimeFromTransactionTime returns unix time from the transaction time

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 Int64Sort added in v0.6.0

func Int64Sort(items []int64)

Int64Sort sorts the specified array with int64 items

func Int64ToString

func Int64ToString(num int64) string

Int64ToString returns the textual representation of this number

func IntToString added in v0.2.0

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 IsStringOnlyContainsDigits added in v0.6.0

func IsStringOnlyContainsDigits(str string) bool

IsStringOnlyContainsDigits returns whether the specified string only contains digit characters

func IsUnixTimeEqualsYearAndMonth added in v0.4.0

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 IsValidDayMonthYearLongOrShortDateFormat added in v0.6.0

func IsValidDayMonthYearLongOrShortDateFormat(date string) bool

IsValidDayMonthYearLongOrShortDateFormat reports long date is valid format

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 IsValidLongDateFormat added in v0.6.0

func IsValidLongDateFormat(date string) bool

IsValidLongDateFormat reports long date is valid format

func IsValidLongDateTimeFormat added in v0.6.0

func IsValidLongDateTimeFormat(datetime string) bool

IsValidLongDateTimeFormat reports whether long date time is valid format

func IsValidLongDateTimeWithoutSecondFormat added in v0.6.0

func IsValidLongDateTimeWithoutSecondFormat(datetime string) bool

IsValidLongDateTimeWithoutSecondFormat reports long date time without seconds is valid format

func IsValidMonthDayYearLongOrShortDateFormat added in v0.6.0

func IsValidMonthDayYearLongOrShortDateFormat(date string) bool

IsValidMonthDayYearLongOrShortDateFormat reports long date is valid format

func IsValidNickName added in v1.2.0

func IsValidNickName(nickname string) bool

IsValidNickName reports whether user nick name is valid

func IsValidUsername

func IsValidUsername(username string) bool

IsValidUsername reports whether username is valid

func IsValidYearMonthDayLongOrShortDateFormat added in v0.6.0

func IsValidYearMonthDayLongOrShortDateFormat(date string) bool

IsValidYearMonthDayLongOrShortDateFormat reports long date is valid format

func ListFileNamesWithPrefixAndSuffix added in v0.3.0

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 added in v0.4.0

func MD5EncodeToString(data []byte) string

MD5EncodeToString returns a hashed string by md5

func ParseAmount added in v0.6.0

func ParseAmount(amount string) (int64, error)

ParseAmount parses a textual representation of amount

func ParseFirstConsecutiveNumber added in v0.6.0

func ParseFirstConsecutiveNumber(str string) (string, bool)

ParseFirstConsecutiveNumber returns the first consecutive number in the specified string

func ParseFromElapsedSeconds added in v0.4.0

func ParseFromElapsedSeconds(elapsedSeconds int) (string, error)

func ParseFromLongDateFirstTime added in v0.8.0

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

ParseFromLongDateFirstTime parses a formatted string in long date format

func ParseFromLongDateLastTime added in v0.8.0

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

ParseFromLongDateLastTime parses a formatted string in long date format

func ParseFromLongDateTimeInFixedUtcOffset added in v1.3.0

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

ParseFromLongDateTimeInFixedUtcOffset parses a formatted string in long date time format

func ParseFromLongDateTimeInTimeZone added in v1.3.0

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

ParseFromLongDateTimeInTimeZone parses a formatted string in long date time format

func ParseFromLongDateTimeToMaxUnixTime added in v0.4.0

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 added in v0.4.0

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 ParseFromLongDateTimeWithTimezone added in v0.6.0

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

ParseFromLongDateTimeWithTimezone parses a formatted string in long date time format

func ParseFromLongDateTimeWithTimezone2 added in v0.6.0

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

ParseFromLongDateTimeWithTimezone2 parses a formatted string in long date time format

func ParseFromLongDateTimeWithTimezoneRFC3339Format added in v0.10.0

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

ParseFromLongDateTimeWithTimezoneRFC3339Format parses a formatted string in long date time RFC 3378 format

func ParseFromLongDateTimeWithoutSecondInFixedUtcOffset added in v1.3.0

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

ParseFromLongDateTimeWithoutSecondInFixedUtcOffset parses a formatted string in long date time format (no second) with fixed UTC offset

func ParseFromShortDateTimeInFixedUtcOffset added in v1.3.0

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

ParseFromShortDateTimeInFixedUtcOffset parses a formatted string in short date time format with fixed UTC offset

func ParseFromTimezoneOffset

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

ParseFromTimezoneOffset parses a formatted string in timezone offset format

func ParseNumericYearMonth added in v0.5.0

func ParseNumericYearMonth(yearMonth string) (int32, int32, error)

ParseNumericYearMonth returns numeric year and month from textual content

func PrintDataErrorResult

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

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

func PrintDataSuccessResult

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

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

func PrintJSONRPCErrorResult added in v0.10.0

func PrintJSONRPCErrorResult(c *core.WebContext, jsonRPCRequest *core.JSONRPCRequest, err *errs.Error)

PrintJSONRPCErrorResult writes error response in JSON-RPC format to current http context

func PrintJSONRPCSuccessResult added in v0.10.0

func PrintJSONRPCSuccessResult(c *core.WebContext, jsonRPCRequest *core.JSONRPCRequest, result any)

PrintJSONRPCSuccessResult writes success response in JSON-RPC format to current http context

func PrintJsonErrorResult

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

PrintJsonErrorResult writes error response in json format to current http context

func PrintJsonSuccessResult

func PrintJsonSuccessResult(c *core.WebContext, 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 SetEventStreamHeader added in v0.9.0

func SetEventStreamHeader(c *core.WebContext)

SetEventStreamHeader sets the headers for event stream response

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 added in v0.2.0

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 added in v0.2.0

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 ToSet added in v0.6.0

func ToSet(items []int64) map[int64]bool

ToSet returns a map where the keys are the items in the specified array

func ToUniqueInt64Slice

func ToUniqueInt64Slice(items []int64) []int64

ToUniqueInt64Slice returns a int64 array which does not have duplicated items

func TrimTrailingZerosInDecimal added in v0.6.0

func TrimTrailingZerosInDecimal(num string) string

TrimTrailingZerosInDecimal returns a textual number without trailing zeros in decimal

func WriteEventStreamJsonErrorResult added in v0.9.0

func WriteEventStreamJsonErrorResult(c *core.WebContext, originalErr *errs.Error)

func WriteEventStreamJsonSuccessResult added in v0.9.0

func WriteEventStreamJsonSuccessResult(c *core.WebContext, result any)

func WriteFile

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

WriteFile would write file according to specified content

Types

This section is empty.

Jump to

Keyboard shortcuts

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