helper

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 28 Imported by: 19

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidFormatByteUnit = errors.New("byte unit invalid format ex: 123.3MB")
View Source
var ErrInvalidFormatMegaByteUnit = errors.New("megabyte unit invalid format ex: 102.3MB")

Functions

func CleanAllRepeatSpaces

func CleanAllRepeatSpaces(v string) string

CleanAllRepeatSpaces clean all repeat space, ex: Get All Girls in the \n party -> Get All Girls in the party

func CompactString added in v1.7.0

func CompactString(a any) string

CompactString compact string representation of a value. If the value is a valid JSON, it will be compacted to a single line of JSON string. Otherwise, it removes all repeated spaces from the string representation of the value.

func Contains added in v1.3.8

func Contains(a, b any, c ...any) bool

Contains if values passed in parameters B and C contain the value of parameter A, it returns true, otherwise it returns false

func ContainsIgnoreCase added in v1.3.8

func ContainsIgnoreCase(a, b any, c ...any) bool

ContainsIgnoreCase if values passed in parameters B and C contain the value of parameter A, it returns true, otherwise it returns false

func ConvertByteUnitStrToFloat added in v1.6.1

func ConvertByteUnitStrToFloat(a any) (float64, error)

ConvertByteUnitStrToFloat convert byte unit text to int ex: 1KB = 1024.0

func ConvertFileToBytes added in v1.0.6

func ConvertFileToBytes(file *os.File) ([]byte, error)

ConvertFileToBytes convert os.File value to slice byte

func ConvertMegaByteUnitStrToFloat added in v1.6.2

func ConvertMegaByteUnitStrToFloat(a any) (float64, error)

ConvertMegaByteUnitStrToFloat convert megabyte unit text to int ex: 1GB = 1024

func ConvertPointerToValue added in v1.0.7

func ConvertPointerToValue[T any](t *T) T

ConvertPointerToValue convert pointer value to value

func ConvertToBase64 added in v1.0.9

func ConvertToBase64(a any) (string, error)

ConvertToBase64 convert any value to string base64

func ConvertToBool added in v1.0.2

func ConvertToBool(a any) (bool, error)

ConvertToBool convert any value to float

func ConvertToBuffer added in v1.0.7

func ConvertToBuffer(a any) (*bytes.Buffer, error)

ConvertToBuffer convert any value to bytes.Buffer

func ConvertToByteUnitStr added in v1.6.1

func ConvertToByteUnitStr(a any) string

ConvertToByteUnitStr takes an integer value in bytes and converts it to a human-readable byte unit string. If the value is less than 1024, it returns the value with the unit "B" appended. If the value is greater than or equal to 1024, it calculates the appropriate unit (KB, MB, GB, etc.) and returns the value with the corresponding unit appended. The value is rounded to one decimal place. This function does not handle negative values.

func ConvertToBytes added in v1.0.2

func ConvertToBytes(a any) ([]byte, error)

ConvertToBytes convert any value to bytes

func ConvertToDest added in v1.0.2

func ConvertToDest(a, dest any) error

ConvertToDest convert value to dest param

func ConvertToFile added in v1.0.7

func ConvertToFile(a any) (*os.File, error)

ConvertToFile convert any value to os.File .txt base64

func ConvertToFloat added in v1.0.2

func ConvertToFloat(a any) (float64, error)

ConvertToFloat convert any value to float

func ConvertToInt added in v1.0.2

func ConvertToInt(a any) (int, error)

ConvertToInt convert any value to int

func ConvertToMegaByteUnitStr added in v1.6.1

func ConvertToMegaByteUnitStr(a any) string

ConvertToMegaByteUnitStr converts an integer value to a string representation in megabyte units. It takes in a parameter `a` which can be of any type that can be converted to an integer. The function returns a string representation of the passed value in megabyte units. If the value is less than 1MB, it returns the value followed by the string "B" (e.g. "256B"). If the value is greater than or equal to 1MB, it converts the value to the nearest megabyte, appends the appropriate unit symbol (K, M, G, T, P, E, Z, Y) based on the magnitude of the value, and appends the string "B" at the end (e.g. "4.5MB", "10.2GB", "3.7TB", etc.).

func ConvertToObjectId

func ConvertToObjectId(a any) (primitive.ObjectID, error)

ConvertToObjectId convert any value to primitive.ObjectID

func ConvertToPointer

func ConvertToPointer[T any](t T) *T

ConvertToPointer convert any value to pointer

func ConvertToPrimitiveDateTime added in v1.1.7

func ConvertToPrimitiveDateTime(a any) (primitive.DateTime, error)

ConvertToPrimitiveDateTime convert any value to primitive.DateTime

func ConvertToReader added in v1.0.7

func ConvertToReader(a any) (*bytes.Reader, error)

ConvertToReader convert any value to io.Reader

func ConvertToString

func ConvertToString(a any) (string, error)

ConvertToString convert any value to beautiful string

func ConvertToTime

func ConvertToTime(a any) (time.Time, error)

ConvertToTime convert any value to time

func ConvertToTimeDuration added in v1.6.7

func ConvertToTimeDuration(a any) (time.Duration, error)

ConvertToTimeDuration convert any value to time duration

func Equals added in v1.2.9

func Equals(a, b any, c ...any) bool

Equals compare values if are equals return true, otherwise return false

func EqualsIgnoreCase added in v1.2.9

func EqualsIgnoreCase(a, b any, c ...any) bool

EqualsIgnoreCase compare values if are equals ignoring case return true, otherwise return false

func EqualsLen added in v1.4.0

func EqualsLen(a any, len int) bool

EqualsLen compares whether the size of the value of parameter A is equal to the suggested len parameter.

func FormatCnpj

func FormatCnpj(v string) string

FormatCnpj format string to cnpj if valid ex: 45991590000108 -> 45.991.590/0001-08

func FormatCpf

func FormatCpf(v string) string

FormatCpf format string to cpf if valid ex: 02104996642 -> 021.049.966-43

func FormatEFloat32

func FormatEFloat32(v float32) string

FormatEFloat32 format float64 to string ex: 3.1415926535 -> "3.1415927E+00"

func FormatEFloat64

func FormatEFloat64(v float64) string

FormatEFloat64 format float64 to string ex: 3.1415926535 -> "3.1415926535E+00"

func FormatFloat32

func FormatFloat32(v float32) string

FormatFloat32 format float32 to string ex: 3.1415926535 -> "3.1415926535"

func FormatFloat64

func FormatFloat64(v float64) string

FormatFloat64 format float64 to string ex: 3.1415926535 -> "3.1415926535"

func FormatMoney

func FormatMoney(v float64, precision int, symbol, thousand, decimal string) string

FormatMoney format float to string money

Usage:

result := FormatMoney(12.23, 2, "R$" , ".", "," )

log.Println("money result:", result)

Output:

[INFO 2023/12/24 08:26:38] money result: R$ 12,23

func FormatMoneyBr added in v1.4.3

func FormatMoneyBr(v float64) string

FormatMoneyBr format float to string money

Usage:

result := FormatMoneyBr(12.23)

log.Println("money result:", result)

Output:

[INFO 2023/12/24 08:26:38] money result: R$ 12,23

func FormatPercentage

func FormatPercentage(v float64, precision int) string

FormatPercentage format float to string percentage ex: 12.23 -> "12,23%"

func FormatPhoneNumber

func FormatPhoneNumber(v, defaultRegion string) string

FormatPhoneNumber format string to international phone number if valid value string ex: 47997576130 -> +55 47 99757-6130

func FormatPhoneNumberNational

func FormatPhoneNumberNational(v, defaultRegion string) string

FormatPhoneNumberNational format string to national phone number ex: 47997576130 -> 47 99757-6130

func GetCallerInfo added in v1.1.8

func GetCallerInfo(skip int) (fileName string, line string, funcName string)

func GetFileJson

func GetFileJson(uri string, dest any) error

GetFileJson get file by uri string param, fill dest by file json

func GetFileString

func GetFileString(uri string) (string, error)

GetFileString get file by uri string param

func GetFirstLastName

func GetFirstLastName(a any) string

GetFirstLastName get first and last name by string value or string pointer, ex: Gabriel Henrique Cataldo -> Gabriel Cataldo.

func HideCnpj

func HideCnpj(v string, maskStart bool) string

HideCnpj formats and partially hides the value ex: 45991590000108 to 45.991.590/****-**

func HideCpf

func HideCpf(v string, maskStart bool) string

HideCpf formats and partially hides the value ex: 02104996643 to 021.049.***-*

func HideEmail

func HideEmail(v string, maskStart bool) string

HideEmail partially hide the value email if it is a valid if maskStart param is true

ex: gabrielcataldo@gmail.com to ***********do@gmail.com

if masStart param is false (default)

ex: gabrielcataldo@gmail.com to gabrielcatal**@*****.***

func HidePhoneNumber

func HidePhoneNumber(v, defaultRegion string, maskStart bool) string

HidePhoneNumber international format of the phone number and partially hide the value if it is a valid phone number ex: 47997576130 to +55 47 99757-****

func HidePhoneNumberNational

func HidePhoneNumberNational(v, defaultRegion string, maskStart bool) string

HidePhoneNumberNational national format of the phone number and partially hide the value if it is a valid phone number ex: 47997576130 to 47 99757-****

func IfEmptyReturns added in v1.3.0

func IfEmptyReturns[T any](a T, b T) T

IfEmptyReturns if A is empty return B value, otherwise return A value

func IfNilReturns added in v1.3.0

func IfNilReturns[T any](a *T, b T) T

IfNilReturns if A is nil return value B, otherwise return A value

func IsAfter

func IsAfter(a, b any) bool

IsAfter If parameter A is after parameter B it will return true, otherwise it will return false.

func IsAfterDate

func IsAfterDate(a, b any) bool

IsAfterDate If parameter A has a date after the date of parameter B, it returns true, otherwise it will return false.

func IsAfterDateToday

func IsAfterDateToday(a any) bool

IsAfterDateToday If the parameter entered is after today it will return true, otherwise it will return false

func IsAfterNow

func IsAfterNow(a any) bool

IsAfterNow if the parameter entered was after now it will return true, otherwise it will return false

func IsAndroidDeviceId added in v1.0.9

func IsAndroidDeviceId(a any) bool

IsAndroidDeviceId If value string is android device id hex return true, otherwise return false

func IsBCrypt

func IsBCrypt(a any) bool

IsBCrypt If value is string bcrypt return true, otherwise return false

func IsBase64

func IsBase64(a any) bool

IsBase64 If value is string base64 return true, otherwise return false

func IsBearer

func IsBearer(a any) bool

IsBearer If value is string bearer return true, otherwise return false

func IsBefore

func IsBefore(a, b any) bool

IsBefore If parameter A is before parameter B it will return true, otherwise it will return false.

func IsBeforeDate

func IsBeforeDate(a, b any) bool

IsBeforeDate If parameter A has a date before the date of parameter B, it returns true, otherwise it will return false.

func IsBeforeDateToday

func IsBeforeDateToday(a any) bool

IsBeforeDateToday If the parameter entered is before today it will return true, otherwise it will return false

func IsBeforeNow

func IsBeforeNow(a any) bool

IsBeforeNow if the parameter entered was before now it will return true, otherwise it will return false

func IsBirthDate added in v1.0.9

func IsBirthDate(a any) bool

IsBirthDate If value time is before today return true, otherwise return false

func IsBool

func IsBool(a any) bool

IsBool check if value is bool return true, otherwise return false.

func IsBoolType added in v1.6.5

func IsBoolType(a any) bool

IsBoolType If value is bool return true, otherwise return false

func IsBufferType added in v1.6.5

func IsBufferType(a any) bool

IsBufferType If value is bytes.Buffer return true, otherwise return false

func IsByteUnit added in v1.6.7

func IsByteUnit(a any) bool

IsByteUnit check if value is string byte unit (ex: "12MB") return true, otherwise return false.

func IsBytesType added in v1.6.5

func IsBytesType(a any) bool

IsBytesType If value is slice byte return true, otherwise return false

func IsChanType added in v1.6.5

func IsChanType(a any) bool

IsChanType If value is chan return true, otherwise return false

func IsCnpj

func IsCnpj(a any) bool

IsCnpj If value is cnpj return true, otherwise return false

func IsCpf

func IsCpf(a any) bool

IsCpf If value is cpf return true, otherwise return false

func IsCpfCnpj added in v1.0.9

func IsCpfCnpj(a any) bool

IsCpfCnpj If value is cpf or cnpj return true, otherwise return false

func IsEmail

func IsEmail(a any) bool

IsEmail If value is email return true, otherwise return false

func IsEmpty

func IsEmpty(a any, b ...any) bool

IsEmpty check all value are empty

func IsErrorType added in v1.6.5

func IsErrorType(a any) bool

IsErrorType If value is error return true, otherwise return false

func IsFileType added in v1.6.5

func IsFileType(a any) bool

IsFileType If value is os.File return true, otherwise return false

func IsFloat

func IsFloat(a any) bool

IsFloat check if value is float return true, otherwise return false.

func IsFloat32Type added in v1.6.5

func IsFloat32Type(a any) bool

IsFloat32Type If value is float32 return true, otherwise return false

func IsFloat64Type added in v1.6.5

func IsFloat64Type(a any) bool

IsFloat64Type If value is float64 return true, otherwise return false

func IsFloatType added in v1.6.5

func IsFloatType(a any) bool

IsFloatType If value is float32 or float64 return true, otherwise return false

func IsFullName added in v1.0.9

func IsFullName(a any) bool

IsFullName If value contains first name and last name return true, otherwise return false

func IsFullNow

func IsFullNow(a any) bool

IsFullNow If the parameter entered is now it will return true, otherwise it will return false

func IsFuncType added in v1.6.5

func IsFuncType(a any) bool

IsFuncType If value is func return true, otherwise return false

func IsGreaterThan added in v1.2.8

func IsGreaterThan(a, b any, c ...any) bool

IsGreaterThan compares whether A is greater than all values passed in other parameters, if the value is not numeric, let's use the Len function and compare the size

func IsGreaterThanOrEqual added in v1.2.8

func IsGreaterThanOrEqual(a, b any, c ...any) bool

IsGreaterThanOrEqual compares whether A is greater than or equal to all values passed in others params, If the value is not numeric, let's use the Len function and compare the size

func IsHttpMethod added in v1.7.1

func IsHttpMethod(a any) bool

IsHttpMethod checks whether the given value represents a valid HTTP method. It converts the value to a string and compares it with predefined HTTP method constants. Returns true if the value is a valid HTTP method, otherwise returns false.

func IsIOSDeviceId added in v1.1.0

func IsIOSDeviceId(a any) bool

IsIOSDeviceId If value string is ios device id hex return true, otherwise return false

func IsInt

func IsInt(a any) bool

IsInt check if value is int return true, otherwise return false.

func IsInt16Type added in v1.6.5

func IsInt16Type(a any) bool

IsInt16Type If value is int16 return true, otherwise return false

func IsInt32Type added in v1.6.5

func IsInt32Type(a any) bool

IsInt32Type If value is int32 return true, otherwise return false

func IsInt64Type added in v1.6.5

func IsInt64Type(a any) bool

IsInt64Type If value is int64 return true, otherwise return false

func IsInt8Type added in v1.6.5

func IsInt8Type(a any) bool

IsInt8Type If value is int8 return true, otherwise return false

func IsIntType added in v1.6.5

func IsIntType(a any) bool

IsIntType If value is int, int8, int16, int32 or int64 return true, otherwise return false

func IsInterfaceType added in v1.6.5

func IsInterfaceType(a any) bool

IsInterfaceType If value is interface return true, otherwise return false

func IsJson

func IsJson(a any) bool

IsJson check if value is json valid return true, otherwise return false.

func IsJsonType added in v1.6.5

func IsJsonType(a any) bool

IsJsonType If value is struct, map, slice or array return true, otherwise return false

func IsLessThan added in v1.2.8

func IsLessThan(a, b any, c ...any) bool

IsLessThan compares whether A is less than all values passed in others params, If the value is not numeric, let's use the Len function and compare the size

func IsLessThanOrEqual added in v1.2.8

func IsLessThanOrEqual(a, b any, c ...any) bool

IsLessThanOrEqual compares whether A is less than or equal to all values passed in others params, If the value is not numeric, let's use the Len function and compare the size

func IsLetter

func IsLetter(a any) bool

IsLetter check any value is letter, ex: v any is int return false, if string letter return true, if bool return true.

func IsMap

func IsMap(a any) bool

IsMap check if value is map return true, otherwise return false.

func IsMapType added in v1.6.5

func IsMapType(a any) bool

IsMapType If value is map return true, otherwise return false

func IsMegabyteUnit added in v1.6.7

func IsMegabyteUnit(a any) bool

IsMegabyteUnit check if value is string megabyte unit (ex: "12TB") return true, otherwise return false.

func IsMobilePlatform added in v1.0.9

func IsMobilePlatform(a any) bool

IsMobilePlatform If value string is "android", "ios" or "iphone os" (independently we always count lowercase) return true, otherwise return false

func IsNil

func IsNil(a any, b ...any) bool

IsNil check all values are nil

func IsNotAndroidDeviceId added in v1.0.9

func IsNotAndroidDeviceId(a any) bool

IsNotAndroidDeviceId If value string is not android device id hex return true, otherwise return false

func IsNotBCrypt added in v1.0.9

func IsNotBCrypt(a any) bool

IsNotBCrypt If value is not string bcrypt return true, otherwise return false

func IsNotBase64 added in v1.0.9

func IsNotBase64(a any) bool

IsNotBase64 If value is not string base64 return true, otherwise return false

func IsNotBearer added in v1.0.9

func IsNotBearer(a any) bool

IsNotBearer If value is not string bearer return true, otherwise return false

func IsNotBirthDate added in v1.0.9

func IsNotBirthDate(a any) bool

IsNotBirthDate If value time is before today return true, otherwise return false

func IsNotBool added in v1.0.2

func IsNotBool(a any) bool

IsNotBool check if value is not bool return true, otherwise return false.

func IsNotBoolType added in v1.6.5

func IsNotBoolType(a any) bool

IsNotBoolType If value is not bool return true, otherwise return false

func IsNotBufferType added in v1.6.5

func IsNotBufferType(a any) bool

IsNotBufferType If value is bytes.Buffer return true, otherwise return false

func IsNotByteUnit added in v1.6.7

func IsNotByteUnit(a any) bool

IsNotByteUnit check if value is not string byte unit (ex: "12MB") return true, otherwise return false.

func IsNotBytesType added in v1.6.5

func IsNotBytesType(a any) bool

IsNotBytesType If value is not slice byte return true, otherwise return false

func IsNotChanType added in v1.6.5

func IsNotChanType(a any) bool

IsNotChanType If value is not chan return true, otherwise return false

func IsNotCnpj added in v1.0.9

func IsNotCnpj(a any) bool

IsNotCnpj If value is not cnpj return true, otherwise return false

func IsNotCpf added in v1.0.9

func IsNotCpf(a any) bool

IsNotCpf If value is not cpf return true, otherwise return false

func IsNotCpfCnpj added in v1.0.9

func IsNotCpfCnpj(a any) bool

IsNotCpfCnpj If value is not cpf or cnpj return true, otherwise return false

func IsNotEmail added in v1.0.9

func IsNotEmail(a any) bool

IsNotEmail If value is not email return true, otherwise return false

func IsNotEmpty

func IsNotEmpty(a any, b ...any) bool

IsNotEmpty check all values are not empty

func IsNotEqualTo added in v1.2.9

func IsNotEqualTo(a, b any, c ...any) bool

IsNotEqualTo compare values if aren't equals return true, otherwise return false

func IsNotEqualToIgnoreCase added in v1.2.9

func IsNotEqualToIgnoreCase(a, b any, c ...any) bool

IsNotEqualToIgnoreCase compare values if aren't equals ignoring case return true, otherwise return false

func IsNotEqualsLen added in v1.4.0

func IsNotEqualsLen(a any, len int) bool

IsNotEqualsLen compares whether the size of the value of parameter A is not equal to the suggested len parameter.

func IsNotErrorType added in v1.6.5

func IsNotErrorType(a any) bool

IsNotErrorType If value is not error return true, otherwise return false

func IsNotFileType added in v1.6.5

func IsNotFileType(a any) bool

IsNotFileType If value is os.File return true, otherwise return false

func IsNotFloat added in v1.0.2

func IsNotFloat(a any) bool

IsNotFloat check if value is not float return true, otherwise return false.

func IsNotFloat32Type added in v1.6.5

func IsNotFloat32Type(a any) bool

IsNotFloat32Type If value is not float32 return true, otherwise return false

func IsNotFloat64Type added in v1.6.5

func IsNotFloat64Type(a any) bool

IsNotFloat64Type If value is not float64 return true, otherwise return false

func IsNotFloatType added in v1.6.5

func IsNotFloatType(a any) bool

IsNotFloatType If value is not float32 or float64 return true, otherwise return false

func IsNotFullName added in v1.0.9

func IsNotFullName(a any) bool

IsNotFullName If value not contains first name and last name return true, otherwise return false

func IsNotFuncType added in v1.6.5

func IsNotFuncType(a any) bool

IsNotFuncType If value is not func return true, otherwise return false

func IsNotHttpMethod added in v1.7.1

func IsNotHttpMethod(a any) bool

IsNotHttpMethod checks whether the given value is not a valid HTTP method. It negates the result of the IsHttpMethod function. Returns true if the value is not a valid HTTP method, otherwise returns false.

func IsNotIOSDeviceId added in v1.0.9

func IsNotIOSDeviceId(a any) bool

IsNotIOSDeviceId If value string is not ios device id hex return true, otherwise return false

func IsNotInt added in v1.0.2

func IsNotInt(a any) bool

IsNotInt check if value is not int return true, otherwise return false.

func IsNotInt16Type added in v1.6.5

func IsNotInt16Type(a any) bool

IsNotInt16Type If value is not int16 return true, otherwise return false

func IsNotInt32Type added in v1.6.5

func IsNotInt32Type(a any) bool

IsNotInt32Type If value is not int32 return true, otherwise return false

func IsNotInt64Type added in v1.6.5

func IsNotInt64Type(a any) bool

IsNotInt64Type If value is not int64 return true, otherwise return false

func IsNotInt8Type added in v1.6.5

func IsNotInt8Type(a any) bool

IsNotInt8Type If value is not int8 return true, otherwise return false

func IsNotIntType added in v1.6.5

func IsNotIntType(a any) bool

IsNotIntType If value is not int, int8, int16, int32 or int64 return true, otherwise return false

func IsNotInterfaceType added in v1.6.5

func IsNotInterfaceType(a any) bool

IsNotInterfaceType If value is interface return true, otherwise return false

func IsNotJson added in v1.0.2

func IsNotJson(a any) bool

IsNotJson check if value is not json return true, otherwise return false.

func IsNotJsonType added in v1.6.5

func IsNotJsonType(a any) bool

IsNotJsonType If value is not struct, map, slice or array return true, otherwise return false

func IsNotMap added in v1.0.2

func IsNotMap(a any) bool

IsNotMap check if value is not map return true, otherwise return false.

func IsNotMapType added in v1.6.5

func IsNotMapType(a any) bool

IsNotMapType If value is not map return true, otherwise return false

func IsNotMegabyteUnit added in v1.6.7

func IsNotMegabyteUnit(a any) bool

IsNotMegabyteUnit check if value is not string megabyte unit (ex: "12MB") return true, otherwise return false.

func IsNotMobilePlatform added in v1.0.9

func IsNotMobilePlatform(a any) bool

IsNotMobilePlatform If value string is not "android", "ios" or "iphone os" (independently we always count lowercase) return true, otherwise return false

func IsNotNil

func IsNotNil(a any, b ...any) bool

IsNotNil check all values are not nil

func IsNotObjectIdType added in v1.6.5

func IsNotObjectIdType(a any) bool

IsNotObjectIdType If value is not primitive.ObjectID return true, otherwise return false

func IsNotPhoneNumber added in v1.0.9

func IsNotPhoneNumber(a any, defaultRegion string) bool

IsNotPhoneNumber If value is not phone number by region return true, otherwise return false

func IsNotPointerType added in v1.6.5

func IsNotPointerType(a any) bool

IsNotPointerType If value is not pointer return true, otherwise return false

func IsNotPostalCode added in v1.0.9

func IsNotPostalCode(a any) bool

IsNotPostalCode If value is not postal code return true, otherwise return false

func IsNotPostalCodePerCountry added in v1.0.9

func IsNotPostalCodePerCountry(a any, countryIso string) bool

IsNotPostalCodePerCountry If value is not postal code per country return true, otherwise return false

func IsNotPrimitiveDateTimeType added in v1.6.5

func IsNotPrimitiveDateTimeType(a any) bool

IsNotPrimitiveDateTimeType If value is not primitive.DateTime return true, otherwise return false

func IsNotPrivateIp added in v1.0.9

func IsNotPrivateIp(a any) bool

IsNotPrivateIp check value is private ip

func IsNotReaderType added in v1.6.5

func IsNotReaderType(a any) bool

IsNotReaderType If value is io.Reader return true, otherwise return false

func IsNotSlice added in v1.0.2

func IsNotSlice(a any) bool

IsNotSlice check if value is not slice return true, otherwise return false.

func IsNotSliceOfMaps added in v1.6.5

func IsNotSliceOfMaps(a any) bool

IsNotSliceOfMaps check if value is not slice of maps return true, otherwise return false.

func IsNotSliceOfMapsType added in v1.6.6

func IsNotSliceOfMapsType(a any) bool

IsNotSliceOfMapsType If value is not slice or array of maps return true, otherwise return false

func IsNotSliceType added in v1.6.5

func IsNotSliceType(a any) bool

IsNotSliceType If value is not slice or array return true, otherwise return false

func IsNotStringType added in v1.6.5

func IsNotStringType(a any) bool

IsNotStringType If value is not string return true, otherwise return false

func IsNotStructType added in v1.6.5

func IsNotStructType(a any) bool

IsNotStructType If value is not struct return true, otherwise return false

func IsNotTime added in v1.0.2

func IsNotTime(a any) bool

IsNotTime check if value is not time return true, otherwise return false.

func IsNotTimeDurationType added in v1.6.7

func IsNotTimeDurationType(a any) bool

IsNotTimeDurationType If value is not time duration return true, otherwise return false

func IsNotTimeType added in v1.6.5

func IsNotTimeType(a any) bool

IsNotTimeType If value is not time return true, otherwise return false

func IsNotUint16Type added in v1.6.5

func IsNotUint16Type(a any) bool

IsNotUint16Type If value is not uint16 return true, otherwise return false

func IsNotUint32Type added in v1.6.5

func IsNotUint32Type(a any) bool

IsNotUint32Type If value is not uint32 return true, otherwise return false

func IsNotUint64Type added in v1.6.5

func IsNotUint64Type(a any) bool

IsNotUint64Type If value is not uint64 return true, otherwise return false

func IsNotUint8Type added in v1.6.5

func IsNotUint8Type(a any) bool

IsNotUint8Type If value is not uint8 return true, otherwise return false

func IsNotUintType added in v1.6.5

func IsNotUintType(a any) bool

IsNotUintType If value is not uint, uint8, uint16, uint32 or uint64 return true, otherwise return false

func IsNotUrl added in v1.0.9

func IsNotUrl(a any) bool

IsNotUrl If value is not url return true, otherwise return false ex: "google.com" = false

func IsNotUrlPath added in v1.6.7

func IsNotUrlPath(a any) bool

IsNotUrlPath check any value is not url path

func IsNow

func IsNow(a any) bool

IsNow If the parameter entered is now (not counting the nanosecond) it will return true, otherwise it will return false

func IsNumeric

func IsNumeric(a any) bool

IsNumeric check any value is numeric, ex: v any is int return true, if string numeric return true, if bool return false.

func IsObjectIdType added in v1.6.5

func IsObjectIdType(a any) bool

IsObjectIdType If value is primitive.ObjectID return true, otherwise return false

func IsPhoneNumber

func IsPhoneNumber(a any, defaultRegion string) bool

IsPhoneNumber If value is phone number by region return true, otherwise return false

func IsPointerType added in v1.6.5

func IsPointerType(a any) bool

IsPointerType If value is pointer return true, otherwise return false

func IsPostalCode

func IsPostalCode(a any) bool

IsPostalCode If value is postal code return true, otherwise return false

func IsPostalCodePerCountry

func IsPostalCodePerCountry(a any, countryIso string) bool

IsPostalCodePerCountry If value is postal code per country return true, otherwise return false

func IsPrimitiveDateTimeType added in v1.6.5

func IsPrimitiveDateTimeType(a any) bool

IsPrimitiveDateTimeType If value is primitive.DateTime return true, otherwise return false

func IsPrivateIp added in v1.0.9

func IsPrivateIp(a any) bool

IsPrivateIp check value is private ip

func IsReaderType added in v1.6.5

func IsReaderType(a any) bool

IsReaderType If value is io.Reader return true, otherwise return false

func IsSlice

func IsSlice(a any) bool

IsSlice check if value is slice return true, otherwise return false.

func IsSliceOfMaps added in v1.6.5

func IsSliceOfMaps(a any) bool

IsSliceOfMaps check if string value is slice of maps return true, otherwise return false.

func IsSliceOfMapsType added in v1.6.6

func IsSliceOfMapsType(a any) bool

IsSliceOfMapsType If value is slice or array of maps return true, otherwise return false

func IsSliceType added in v1.6.5

func IsSliceType(a any) bool

IsSliceType If value is slice or array return true, otherwise return false

func IsStringType added in v1.6.5

func IsStringType(a any) bool

IsStringType If value is string return true, otherwise return false

func IsStructType added in v1.6.5

func IsStructType(a any) bool

IsStructType If value is struct return true, otherwise return false

func IsTime

func IsTime(a any) bool

IsTime check if value is time return true, otherwise return false.

func IsTimeDurationType added in v1.6.7

func IsTimeDurationType(a any) bool

IsTimeDurationType If value is time duration return true, otherwise return false

func IsTimeType added in v1.6.5

func IsTimeType(a any) bool

IsTimeType If value is time return true, otherwise return false

func IsToday

func IsToday(a any) bool

IsToday If the parameter entered is today it will return true, otherwise it will return false

func IsUint16Type added in v1.6.5

func IsUint16Type(a any) bool

IsUint16Type If value is uint16 return true, otherwise return false

func IsUint32Type added in v1.6.5

func IsUint32Type(a any) bool

IsUint32Type If value is uint32 return true, otherwise return false

func IsUint64Type added in v1.6.5

func IsUint64Type(a any) bool

IsUint64Type If value is uint64 return true, otherwise return false

func IsUint8Type added in v1.6.5

func IsUint8Type(a any) bool

IsUint8Type If value is uint8 return true, otherwise return false

func IsUintType added in v1.6.5

func IsUintType(a any) bool

IsUintType If value is uint, uint8, uint16, uint32 or uint64 return true, otherwise return false

func IsUrl

func IsUrl(a any) bool

IsUrl If value is url return true, otherwise return false ex: "google.com" = true

func IsUrlPath added in v1.6.7

func IsUrlPath(a any) bool

IsUrlPath check any value is url path ex: "/api/users"

func Len added in v1.3.8

func Len(a any) int

Len retrieves the size of the passed value, if it is not a slice, struct or map, the size of the parameter converted to a string is returned.

func MaskStartOrEndOfString

func MaskStartOrEndOfString(s string, mask rune, maskStart bool) string

MaskStartOrEndOfString mask start or end of string

Parameters

- s: string value - mask: character to replace - maskStart: if true mask start value, otherwise mask end value

func MaxFloat32 added in v1.5.8

func MaxFloat32(v, max float32) float32

MaxFloat32 max float, if v is less than max, max will prevail

func MaxFloat64 added in v1.5.8

func MaxFloat64(v, max float64) float64

MaxFloat64 max float, if v is less than max, max will prevail

func MaxInt

func MaxInt(v, max int) int

MaxInt max int, if v is less than max, max will prevail

func MaxInt32

func MaxInt32(v, max int32) int32

MaxInt32 max int, if v is less than max, max will prevail

func MaxInt64

func MaxInt64(v, max int64) int64

MaxInt64 max int, if v is less than max, max will prevail

func MinFloat32 added in v1.5.8

func MinFloat32(v, min float32) float32

MinFloat32 min float, if v is greater than min, min will prevail

func MinFloat64 added in v1.5.8

func MinFloat64(v, min float64) float64

MinFloat64 min float, if v is greater than min, min will prevail

func MinInt

func MinInt(v, min int) int

MinInt min int, if v is greater than min, min will prevail

func MinInt32

func MinInt32(v, min int32) int32

MinInt32 min int, if v is greater than min, min will prevail

func MinInt64

func MinInt64(v, min int64) int64

MinInt64 min int, if v is greater than min, min will prevail

func NotContains added in v1.3.8

func NotContains(a, b any, c ...any) bool

NotContains if values passed in parameters B and C do not contain the value of parameter A, it returns true, otherwise it returns false

func NotContainsIgnoreCase added in v1.3.8

func NotContainsIgnoreCase(a, b any, c ...any) bool

NotContainsIgnoreCase if values passed in parameters B and C do not contain the value of parameter A, it returns true, otherwise it returns false

func RandomBool

func RandomBool() bool

RandomBool return random value bool

func RandomNumber

func RandomNumber(min, max int) int

RandomNumber random number generator with range min and max

func RandomNumberStr

func RandomNumberStr(min, max int) string

RandomNumberStr generate random numbers string by min and max parameters

func ReturnNonEmptyValue added in v1.3.0

func ReturnNonEmptyValue[T any](a ...T) T

ReturnNonEmptyValue returns the information value that is not empty

func ReturnNonNilValue added in v1.3.0

func ReturnNonNilValue[T any](a ...T) T

ReturnNonNilValue returns the information value that is not nil

func Round

func Round(v float64, precision int) float64

Round rounding by value ex: 1.3 -> 1 or 1.6 -> 2

func RoundDown

func RoundDown(v float64, precision int) float64

RoundDown rounding down ex: 1.5 -> 1

func RoundUp

func RoundUp(v float64, precision int) float64

RoundUp rounding up ex: 1.5 -> 2

func SimpleConvertByteUnitStrToFloat added in v1.6.1

func SimpleConvertByteUnitStrToFloat(a any) float64

SimpleConvertByteUnitStrToFloat convert byte unit text to int ex: 1KB = 1024, if err return empty value

func SimpleConvertFileToBytes added in v1.0.6

func SimpleConvertFileToBytes(file *os.File) []byte

SimpleConvertFileToBytes convert os.File value to slice byte, without error

func SimpleConvertMegaByteUnitStrToFloat added in v1.6.2

func SimpleConvertMegaByteUnitStrToFloat(a any) float64

SimpleConvertMegaByteUnitStrToFloat convert megabyte unit text to int ex: 1GB = 1024, if err return empty value

func SimpleConvertToBase64 added in v1.0.9

func SimpleConvertToBase64(a any) string

SimpleConvertToBase64 convert any value to string base64, without error

func SimpleConvertToBool added in v1.0.3

func SimpleConvertToBool(a any) bool

SimpleConvertToBool convert any value to float, if err return empty value

func SimpleConvertToBuffer added in v1.0.7

func SimpleConvertToBuffer(a any) *bytes.Buffer

SimpleConvertToBuffer convert any value to bytes.Buffer, without error

func SimpleConvertToBytes added in v1.0.3

func SimpleConvertToBytes(a any) []byte

SimpleConvertToBytes convert any value to bytes, if err return empty value

func SimpleConvertToDest added in v1.4.6

func SimpleConvertToDest(a, dest any)

SimpleConvertToDest convert value to dest param without error

func SimpleConvertToFile added in v1.0.7

func SimpleConvertToFile(a any) *os.File

SimpleConvertToFile convert any value to os.File .txt base64, without error

func SimpleConvertToFloat added in v1.0.3

func SimpleConvertToFloat(a any) float64

SimpleConvertToFloat convert any value to float, if err return empty value

func SimpleConvertToInt added in v1.0.3

func SimpleConvertToInt(a any) int

SimpleConvertToInt convert any value to int, if err return empty value

func SimpleConvertToObjectId added in v1.0.3

func SimpleConvertToObjectId(a any) primitive.ObjectID

SimpleConvertToObjectId convert any value to primitive.ObjectID, if err return empty value, check using primitive.NilObjectID

func SimpleConvertToPrimitiveDateTime added in v1.1.7

func SimpleConvertToPrimitiveDateTime(a any) primitive.DateTime

SimpleConvertToPrimitiveDateTime convert any value to primitive.DateTime, if err return empty value

func SimpleConvertToReader added in v1.0.7

func SimpleConvertToReader(a any) *bytes.Reader

SimpleConvertToReader convert any value to bytes.Reader, without error

func SimpleConvertToString added in v1.0.3

func SimpleConvertToString(a any) string

SimpleConvertToString convert any value to beautiful string, if err return empty value

func SimpleConvertToTime added in v1.0.3

func SimpleConvertToTime(a any) time.Time

SimpleConvertToTime convert any value to time, if err return empty value

func SimpleConvertToTimeDuration added in v1.6.7

func SimpleConvertToTimeDuration(a any) time.Duration

SimpleConvertToTimeDuration convert any value to time duration, if err return empty value

func Sprintln added in v1.0.3

func Sprintln(a ...any) string

Sprintln get all values convert to text string

func Validate

func Validate() *validator.Validate

Validate persist custom validator.Validate

Types

type BaseEnum

type BaseEnum interface {
	// IsEnumValid return true if value is valid, using on tag validate "enum"
	IsEnumValid() bool
}

Jump to

Keyboard shortcuts

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