Documentation
¶
Index ¶
- Constants
- Variables
- func Empty(v reflect.Value) bool
- func FormatPhoneE164(str string, region string) (string, error)
- func FormatPhoneInternational(str string, region string) (string, error)
- func FormatPhoneNational(str string, region string) (string, error)
- func InString(str string, params []string) bool
- func IsASCII(str string) bool
- func IsAccepted(i interface{}) bool
- func IsAfter(i interface{}, params []string) (bool, error)
- func IsAfterOrEqual(i interface{}, params []string) (bool, error)
- func IsAlpha(str string) bool
- func IsAlphaDash(str string) bool
- func IsAlphaDashUnicode(str string) bool
- func IsAlphaNum(str string) bool
- func IsAlphaNumUnicode(str string) bool
- func IsAlphaUnicode(str string) bool
- func IsArray(i interface{}) (bool, error)
- func IsBefore(i interface{}, params []string) (bool, error)
- func IsBeforeOrEqual(i interface{}, params []string) (bool, error)
- func IsBetween(i interface{}, params []string) (bool, error)
- func IsBoolean(i interface{}) (bool, error)
- func IsContains(i interface{}, params []string) (bool, error)
- func IsCountryAlpha2(str string) bool
- func IsCountryAlpha3(str string) bool
- func IsCountryCode(str string) bool
- func IsCountryNumeric(str string) bool
- func IsCurrencyAll(str string) bool
- func IsCurrencyCrypto(str string) bool
- func IsCurrencyFiat(str string) bool
- func IsDate(i interface{}) (bool, error)
- func IsDateAfter(value, after time.Time) bool
- func IsDateAfterOrEqual(value, after time.Time) bool
- func IsDateBefore(value, before time.Time) bool
- func IsDateBeforeOrEqual(value, before time.Time) bool
- func IsDateBetween(value, start, end time.Time) bool
- func IsDateBetweenOrEqual(value, start, end time.Time) bool
- func IsDateFormat(i interface{}, params []string) (bool, error)
- func IsDecimalBetween(value, min, max decimal.Decimal) bool
- func IsDecimalEqual(a, b decimal.Decimal) bool
- func IsDecimalGt(a, b decimal.Decimal) bool
- func IsDecimalGte(a, b decimal.Decimal) bool
- func IsDecimalLt(a, b decimal.Decimal) bool
- func IsDecimalLte(a, b decimal.Decimal) bool
- func IsDecimalNegative(value decimal.Decimal) bool
- func IsDecimalPositive(value decimal.Decimal) bool
- func IsDecimalPrecision(i interface{}, params []string) (bool, error)
- func IsDecimalZero(value decimal.Decimal) bool
- func IsDeclined(i interface{}) bool
- func IsDifferent(a, b interface{}) (bool, error)
- func IsDigitsBetween(i interface{}, params []string) (bool, error)
- func IsDistinct(i interface{}) bool
- func IsDoesntContain(i interface{}, params []string) (bool, error)
- func IsDoesntEndWith(str string, params []string) bool
- func IsDoesntStartWith(str string, params []string) bool
- func IsEmail(str string) bool
- func IsEmptyString(str string) bool
- func IsEndsWith(str string, params []string) bool
- func IsFilled(i interface{}) (bool, error)
- func IsFloat(str string) bool
- func IsFloat64Between(value, min, max float64) bool
- func IsFloat64Gt(value, threshold float64) bool
- func IsFloat64Gte(value, threshold float64) bool
- func IsFloat64Lt(value, threshold float64) bool
- func IsFloat64Lte(value, threshold float64) bool
- func IsFuture(value time.Time) bool
- func IsGenericBetween[T NumericType](value, min, max T) bool
- func IsGenericDistinct[T comparable](value []T) bool
- func IsGenericGt[T OrderedType](value, threshold T) bool
- func IsGenericGte[T OrderedType](value, threshold T) bool
- func IsGenericIn[T comparable](value T, allowed []T) bool
- func IsGenericLt[T OrderedType](value, threshold T) bool
- func IsGenericLte[T OrderedType](value, threshold T) bool
- func IsGenericMax[T NumericType](value, max T) bool
- func IsGenericMin[T NumericType](value, min T) bool
- func IsGenericNotIn[T comparable](value T, disallowed []T) bool
- func IsGenericRequired[T comparable](value T) bool
- func IsGenericRequiredMap[K comparable, V any](value map[K]V) bool
- func IsGenericRequiredSlice[T any](value []T) bool
- func IsGt(i, a interface{}) (bool, error)
- func IsGtParam(i interface{}, params []string) (bool, error)
- func IsGte(i, a interface{}) (bool, error)
- func IsGteParam(i interface{}, params []string) (bool, error)
- func IsHexColor(str string) bool
- func IsIP(v string) bool
- func IsIPv4(v string) bool
- func IsIPv6(v string) bool
- func IsImage(data []byte) bool
- func IsIn(i interface{}, params []string) (bool, error)
- func IsInt(str string) bool
- func IsInt64Between(value, min, max int64) bool
- func IsInt64Gt(value, threshold int64) bool
- func IsInt64Gte(value, threshold int64) bool
- func IsInt64Lt(value, threshold int64) bool
- func IsInt64Lte(value, threshold int64) bool
- func IsJSON(i interface{}) (bool, error)
- func IsLanguageAlpha2(str string) bool
- func IsLanguageAlpha3(str string) bool
- func IsLanguageCode(str string) bool
- func IsList(i interface{}) (bool, error)
- func IsLowercase(str string) bool
- func IsLt(i, a interface{}) (bool, error)
- func IsLtParam(i interface{}, params []string) (bool, error)
- func IsLte(i, a interface{}) (bool, error)
- func IsLteParam(i interface{}, params []string) (bool, error)
- func IsMACAddress(str string) bool
- func IsMax(i interface{}, params []string) (bool, error)
- func IsMaxDigits(i interface{}, params []string) (bool, error)
- func IsMimeTypes(data []byte, mimeTypes []string) bool
- func IsMimes(data []byte, mimes []string) (bool, error)
- func IsMin(i interface{}, params []string) (bool, error)
- func IsMinDigits(i interface{}, params []string) (bool, error)
- func IsMissing(i interface{}) bool
- func IsMultipleOf(i interface{}, params []string) (bool, error)
- func IsNotIn(i interface{}, params []string) (bool, error)
- func IsNotRegex(i interface{}, params []string) (bool, error)
- func IsNull(str string) bool
- func IsNumeric(str string) bool
- func IsPast(value time.Time) bool
- func IsPhone(str string, region string) bool
- func IsPhoneE164(str string) bool
- func IsPhoneMobile(str string, region string) bool
- func IsPhoneValid(str string) bool
- func IsPresent(i interface{}) bool
- func IsProhibited(i interface{}) bool
- func IsRegex(i interface{}, params []string) (bool, error)
- func IsRequired(i interface{}) bool
- func IsRequiredArrayKeys(i interface{}, keys []string) (bool, error)
- func IsSame(i, a interface{}) (bool, error)
- func IsSize(i interface{}, params []string) (bool, error)
- func IsStartsWith(str string, params []string) bool
- func IsString(i interface{}) (bool, error)
- func IsStringBetween(v string, left, right int64) bool
- func IsTimezone(str string) bool
- func IsToday(value time.Time) bool
- func IsULID(str string) bool
- func IsURL(str string) bool
- func IsUUID(str string) bool
- func IsUUID3(str string) bool
- func IsUUID4(str string) bool
- func IsUUID5(str string) bool
- func IsUint64Between(value, min, max uint64) bool
- func IsUint64Gt(value, threshold uint64) bool
- func IsUint64Gte(value, threshold uint64) bool
- func IsUint64Lt(value, threshold uint64) bool
- func IsUint64Lte(value, threshold uint64) bool
- func IsUppercase(str string) bool
- func Now() time.Time
- func ToBool(str string) bool
- func ToFloat(str string) (float64, error)
- func ToInt(value interface{}) (res int64, err error)
- func ToString(obj interface{}) string
- func ToUint(param string) (res uint64, err error)
- func Today() time.Time
- func TodayUTC() time.Time
- func Tomorrow() time.Time
- func ValidateStruct(s interface{}) error
- func Yesterday() time.Time
- type CustomTypeValidateFunc
- type DateRule
- func (r *DateRule) After(t time.Time) *DateRule
- func (r *DateRule) AfterOrEqual(t time.Time) *DateRule
- func (r *DateRule) Before(t time.Time) *DateRule
- func (r *DateRule) BeforeOrEqual(t time.Time) *DateRule
- func (r *DateRule) Between(start, end time.Time) *DateRule
- func (r *DateRule) BetweenOrEqual(start, end time.Time) *DateRule
- func (r *DateRule) Validate(t time.Time) bool
- func (r *DateRule) ValidateWithError(t time.Time) error
- type DateValidator
- type ErrorResponse
- type Errors
- func (es Errors) Error() string
- func (es Errors) Errors() []error
- func (es Errors) FieldErrors() []*FieldError
- func (es Errors) GetFieldError(fieldName string) *FieldError
- func (es Errors) GroupByField() map[string][]*FieldError
- func (es Errors) HasFieldError(fieldName string) bool
- func (es Errors) MarshalJSON() ([]byte, error)
- type FieldError
- type FloatType
- type IntegerType
- type MessageParameters
- type NumericType
- type OrderedType
- type ParamValidateFunc
- type StringParamValidateFunc
- type StringValidateFunc
- type TimeHelper
- type Translate
- type Translator
- type UnsupportedTypeError
- type ValidTag
- type ValidateFunc
- type Validator
Constants ¶
const ( Email string = `^[a-zA-Z0-9.!#$%&'*+/=?^_` + "`" + `{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$` Alpha string = "^[a-zA-Z]+$" AlphaNum string = "^[a-zA-Z0-9]+$" AlphaDash string = "^[a-zA-Z_-]+$" AlphaUnicode string = "^[\\p{L}]+$" AlphaNumUnicode string = "^[\\p{L}\\p{M}\\p{N}]+$" AlphaDashUnicode string = "^[\\p{L}\\p{M}\\p{N}_-]+$" Numeric string = "^\\d+$" Int string = "^(?:[-+]?(?:0|[1-9][0-9]*))$" Float string = "^(?:[-+]?(?:[0-9]+))?(?:\\.[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$" Hexadecimal string = "^[0-9a-fA-F]+$" HexColor string = "^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$" RGBColor string = "" /* 167-byte string literal not displayed */ RGBAColor string = "" /* 200-byte string literal not displayed */ HSLColor string = "^hsl\\(\\s*(?:0|[1-9]\\d?|[12]\\d\\d|3[0-5]\\d|360)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*,\\s*(?:(?:0|[1-9]\\d?|100)%)\\s*\\)$" HSLAColor string = "" /* 158-byte string literal not displayed */ UUID3 string = "^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$" UUID4 string = "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$" UUID5 string = "^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$" UUID string = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" ULID string = "^[0-7][0-9A-HJKMNP-TV-Z]{25}$" ASCII string = "^[\x00-\x7F]*$" MACAddress string = "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$|^([0-9A-Fa-f]{4}\\.){2}([0-9A-Fa-f]{4})$" CreditCard string = "^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|3[0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})$" ISBN10 string = "^(?:[0-9]{9}X|[0-9]{10})$" ISBN13 string = "^(?:97[89][0-9]{10})$" IP string = `` /* 659-byte string literal not displayed */ URLSchema string = `((ftp|tcp|udp|wss?|https?):\/\/)` URLUsername string = `(\S+(:\S*)?@)` URLPath string = `((\/|\?|#)[^\s]*)` URLPort string = `(:(\d{1,5}))` URLIP string = `([1-9]\d?|1\d\d|2[01]\d|22[0-3]|24\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){2}(?:\.([0-9]\d?|1\d\d|2[0-4]\d|25[0-5]))` URLSubdomain string = `((www\.)|([a-zA-Z0-9]+([-_\.]?[a-zA-Z0-9])*[a-zA-Z0-9]\.[a-zA-Z0-9]+))` URL = `^` + URLSchema + `?` + URLUsername + `?` + `((` + URLIP + `|(\[` + IP + `\])|(([a-zA-Z0-9]([a-zA-Z0-9-_]+)?[a-zA-Z0-9]([-\.][a-zA-Z0-9]+)*)|(` + URLSubdomain + `?))?(([a-zA-Z\x{00a1}-\x{ffff}0-9]+-?-?)*[a-zA-Z\x{00a1}-\x{ffff}0-9]+)(?:\.([a-zA-Z\x{00a1}-\x{ffff}]{1,}))?))\.?` + URLPort + `?` + URLPath + `?$` )
Basic regular expressions for validating strings Note: Email regex is simplified to prevent ReDoS attacks while maintaining practical validation
const ( // Unknown is unresolved OS type Unknown = iota // Win is Windows type Win // Unix is *nix OS types Unix )
Used by IsFilePath func
Variables ¶
var ( ValidateBetween = IsBetween ValidateDigitsBetween = IsDigitsBetween ValidateSize = IsSize ValidateMax = IsMax ValidateMin = IsMin ValidateGtParam = IsGtParam ValidateGteParam = IsGteParam ValidateLtParam = IsLtParam ValidateLteParam = IsLteParam ValidateSame = IsSame ValidateLt = IsLt ValidateLte = IsLte ValidateGt = IsGt ValidateGte = IsGte ValidateDistinct = IsDistinct ValidateMultipleOf = IsMultipleOf ValidateMaxDigits = IsMaxDigits ValidateMinDigits = IsMinDigits ValidateDecimalPrecision = IsDecimalPrecision ValidateContains = IsContains ValidateDoesntContain = IsDoesntContain ValidateMimeTypes = IsMimeTypes ValidateMimes = IsMimes ValidateImage = IsImage ValidateRequired = IsRequired ValidateAccepted = IsAccepted ValidateDeclined = IsDeclined ValidateProhibited = IsProhibited ValidateMissing = IsMissing ValidatePresent = IsPresent ValidateRequiredArrayKeys = IsRequiredArrayKeys ValidateList = IsList ValidateDate = IsDate ValidateDateFormat = IsDateFormat ValidateAfter = IsAfter ValidateAfterOrEqual = IsAfterOrEqual ValidateBefore = IsBefore ValidateBeforeOrEqual = IsBeforeOrEqual ValidateIn = IsIn ValidateNotIn = IsNotIn ValidateDifferent = IsDifferent ValidateJSON = IsJSON ValidateRegex = IsRegex ValidateNotRegex = IsNotRegex ValidateBoolean = IsBoolean ValidateString = IsString ValidateArray = IsArray ValidateFilled = IsFilled )
var ( DateAfter = IsDateAfter DateAfterOrEqual = IsDateAfterOrEqual DateBefore = IsDateBefore DateBeforeOrEqual = IsDateBeforeOrEqual DateBetween = IsDateBetween DateBetweenOrEqual = IsDateBetweenOrEqual )
var ( IsDecimalRequired = func(v decimal.Decimal) bool { return !v.IsZero() } IsDecimalMin = IsDecimalGte IsDecimalMax = IsDecimalLte ValidateDecimalMin = IsDecimalGte ValidateDecimalMax = IsDecimalLte ValidateDecimalGt = IsDecimalGt ValidateDecimalGte = IsDecimalGte ValidateDecimalLt = IsDecimalLt ValidateDecimalLte = IsDecimalLte ValidateDecimalZero = IsDecimalZero ValidateDecimalBetween = IsDecimalBetween )
Aliases for consistency with other validators.
var ( ValidateDecimalPositive = IsDecimalPositive ValidateDecimalNegative = IsDecimalNegative )
Deprecated aliases for backward compatibility.
var ( IsFloat64Min = IsFloat64Gte IsFloat64Max = IsFloat64Lte )
Aliases for consistency with other validators.
var ( ValidateDigitsBetweenFloat64 = IsFloat64Between ValidateMaxFloat64 = IsFloat64Lte ValidateMinFloat64 = IsFloat64Gte ValidateLtFloat64 = IsFloat64Lt ValidateLteFloat64 = IsFloat64Lte ValidateGteFloat64 = IsFloat64Gte ValidateGtFloat64 = IsFloat64Gt )
Deprecated: Use Is* functions instead.
var ( IsInt64Min = IsInt64Gte IsInt64Max = IsInt64Lte )
Aliases for consistency with other validators.
var ( ValidateBetweenString = IsStringBetween ValidateEmail = IsEmail ValidateAlpha = IsAlpha ValidateAlphaNum = IsAlphaNum ValidateAlphaDash = IsAlphaDash ValidateAlphaUnicode = IsAlphaUnicode ValidateAlphaNumUnicode = IsAlphaNumUnicode ValidateAlphaDashUnicode = IsAlphaDashUnicode ValidateIP = IsIP ValidateIPv4 = IsIPv4 ValidateIPv6 = IsIPv6 ValidateUUID = IsUUID ValidateUUID3 = IsUUID3 ValidateUUID4 = IsUUID4 ValidateUUID5 = IsUUID5 ValidateURL = IsURL ValidateHexColor = IsHexColor ValidateTimezone = IsTimezone ValidateASCII = IsASCII ValidateLowercase = IsLowercase ValidateUppercase = IsUppercase ValidateStartsWith = IsStartsWith ValidateEndsWith = IsEndsWith ValidateDoesntStartWith = IsDoesntStartWith ValidateDoesntEndWith = IsDoesntEndWith ValidateMACAddress = IsMACAddress ValidateULID = IsULID )
Deprecated: Use Is* functions instead.
var ( IsUint64Min = IsUint64Gte IsUint64Max = IsUint64Lte )
Aliases for consistency with other validators.
var CustomTypeRuleMap = &customTypeRuleMap{validateFunc: make(map[string]CustomTypeValidateFunc)}
CustomTypeRuleMap is a map of functions that can be used as tags for ValidateStruct function.
var Default = New()
Default returns a instance of Validator
var MessageMap = map[string]string{}/* 137 elements not displayed */
MessageMap is a map of string, that can be used as error message for ValidateStruct function.
var Mimes = map[string]string{}/* 767 elements not displayed */
Mimes is a map of extension to MIME types.
var ParamRuleMap = map[string]ParamValidateFunc{
"between": isBetween,
"digitsBetween": isDigitsBetween,
"min": isMin,
"max": isMax,
"size": isSize,
"gt": isGtParam,
"gte": isGteParam,
"lt": isLtParam,
"lte": isLteParam,
"multipleOf": isMultipleOf,
"maxDigits": isMaxDigits,
"minDigits": isMinDigits,
"decimal": isDecimalPrecision,
"contains": isContains,
"doesntContain": isDoesntContain,
"requiredArrayKeys": isRequiredArrayKeys,
"dateFormat": isDateFormat,
"after": isAfter,
"afterOrEqual": isAfterOrEqual,
"before": isBefore,
"beforeOrEqual": isBeforeOrEqual,
"in": isIn,
"notIn": isNotIn,
"regex": isRegex,
"notRegex": isNotRegex,
}
ParamRuleMap is a map of functions, that can be used as tags for ValidateStruct function.
var RuleMap = map[string]ValidateFunc{ "distinct": isDistinct, "accepted": func(v reflect.Value) (bool, error) { return isAccepted(v), nil }, "declined": func(v reflect.Value) (bool, error) { return isDeclined(v), nil }, "prohibited": func(v reflect.Value) (bool, error) { return isProhibited(v), nil }, "missing": func(v reflect.Value) (bool, error) { return isMissing(v), nil }, "present": func(v reflect.Value) (bool, error) { return isPresent(v), nil }, "list": isList, "date": isDate, "json": isJSON, "boolean": isBoolean, "string": isString, "array": isArray, "filled": isFilled, }
RuleMap is a map of functions, that can be used as tags for ValidateStruct function.
var StringParamRulesMap = map[string]StringParamValidateFunc{ "startsWith": IsStartsWith, "endsWith": IsEndsWith, "doesntStartWith": IsDoesntStartWith, "doesntEndWith": IsDoesntEndWith, }
StringParamRulesMap is a map of functions with params, that can be used as tags for ValidateStruct function when reflect type is string.
var StringRulesMap = map[string]StringValidateFunc{ "numeric": IsNumeric, "int": IsInt, "integer": IsInt, "float": IsFloat, "email": IsEmail, "alpha": IsAlpha, "alphaNum": IsAlphaNum, "alphaDash": IsAlphaDash, "alphaUnicode": IsAlphaUnicode, "alphaNumUnicode": IsAlphaNumUnicode, "alphaDashUnicode": IsAlphaDashUnicode, "ip": IsIP, "ipv4": IsIPv4, "ipv6": IsIPv6, "uuid3": IsUUID3, "uuid4": IsUUID4, "uuid5": IsUUID5, "uuid": IsUUID, "ulid": IsULID, "url": IsURL, "hexColor": IsHexColor, "timezone": IsTimezone, "ascii": IsASCII, "lowercase": IsLowercase, "uppercase": IsUppercase, "macAddress": IsMACAddress, "country": IsCountryCode, "country.alpha2": IsCountryAlpha2, "country.alpha3": IsCountryAlpha3, "country.numeric": IsCountryNumeric, "currency": IsCurrencyAll, "currency.all": IsCurrencyAll, "currency.fiat": IsCurrencyFiat, "currency.crypto": IsCurrencyCrypto, "language": IsLanguageCode, "language.alpha2": IsLanguageAlpha2, "language.alpha3": IsLanguageAlpha3, "phone.e164": IsPhoneE164, "phone": IsPhoneValid, }
StringRulesMap is a map of functions, that can be used as tags for ValidateStruct function when reflect type is string.
var (
ValidateDigitsBetweenInt64 = IsInt64Between
)
Deprecated: Use Is* functions instead.
var (
ValidateDigitsBetweenUint64 = IsUint64Between
)
Deprecated: Use Is* functions instead.
Functions ¶
func FormatPhoneE164 ¶
FormatPhoneE164 formats phone number to E.164 format
func FormatPhoneInternational ¶
FormatPhoneInternational formats phone number to international format
func FormatPhoneNational ¶
FormatPhoneNational formats phone number to national format
func IsAfterOrEqual ¶
IsAfterOrEqual checks if the date is after or equal to the given date
func IsAlpha ¶
IsAlpha check if the string may be only contains letters (a-zA-Z). Empty string is valid.
func IsAlphaDash ¶
IsAlphaDash check if the string may be only contains letters, numbers, dashes and underscores. Empty string is valid.
func IsAlphaDashUnicode ¶
IsAlphaDashUnicode check if the string may be only contains letters, numbers, dashes and underscores. Empty string is valid.
func IsAlphaNum ¶
IsAlphaNum check if the string may be only contains letters and numbers. Empty string is valid.
func IsAlphaNumUnicode ¶
IsAlphaNumUnicode check if the string may be only contains letters and numbers. Empty string is valid.
func IsAlphaUnicode ¶
IsAlphaUnicode check if the string may be only contains letters (a-zA-Z). Empty string is valid.
func IsBeforeOrEqual ¶
IsBeforeOrEqual checks if the date is before or equal to the given date
func IsBetween ¶
IsBetween check The field under validation must have a size between the given min and max. Strings, numerics, arrays, and files are evaluated in the same fashion as the size rule.
func IsContains ¶
IsContains is the validation function for validating an array/slice contains specified values.
func IsCountryAlpha2 ¶
IsCountryAlpha2 validates ISO 3166-1 alpha-2 country code (2-letter)
func IsCountryAlpha3 ¶
IsCountryAlpha3 validates ISO 3166-1 alpha-3 country code (3-letter)
func IsCountryCode ¶
IsCountryCode validates any ISO 3166-1 country code format
func IsCountryNumeric ¶
IsCountryNumeric validates ISO 3166-1 numeric country code
func IsCurrencyAll ¶
IsCurrencyAll validates any currency (fiat + crypto)
func IsCurrencyCrypto ¶
IsCurrencyCrypto validates cryptocurrency code
func IsCurrencyFiat ¶
IsCurrencyFiat validates ISO 4217 fiat currency code (3-letter)
func IsDateAfter ¶
IsDateAfter checks if the date is after the given time
func IsDateAfterOrEqual ¶
IsDateAfterOrEqual checks if the date is after or equal to the given time
func IsDateBefore ¶
IsDateBefore checks if the date is before the given time
func IsDateBeforeOrEqual ¶
IsDateBeforeOrEqual checks if the date is before or equal to the given time
func IsDateBetween ¶
IsDateBetween checks if the date is between start and end (exclusive)
func IsDateBetweenOrEqual ¶
IsDateBetweenOrEqual checks if the date is between start and end (inclusive)
func IsDateFormat ¶
IsDateFormat checks if the value matches the given date format
func IsDecimalBetween ¶
IsDecimalBetween checks if min <= value <= max.
func IsDecimalEqual ¶
IsDecimalEqual checks if two decimals are equal.
func IsDecimalNegative ¶
IsDecimalNegative checks if value < 0.
func IsDecimalPositive ¶
IsDecimalPositive checks if value > 0.
func IsDecimalPrecision ¶
IsDecimalPrecision is the validation function for validating decimal places.
func IsDecimalZero ¶
IsDecimalZero checks if decimal is zero.
func IsDifferent ¶
IsDifferent checks if the value is different from another value
func IsDigitsBetween ¶
IsDigitsBetween check The field under validation must have a length between the given min and max.
func IsDistinct ¶
func IsDistinct(i interface{}) bool
IsDistinct is the validation function for validating an attribute is unique among other values.
func IsDoesntContain ¶
IsDoesntContain is the validation function for validating an array/slice does not contain specified values.
func IsDoesntEndWith ¶
IsDoesntEndWith check if the string does not end with any of the given suffixes. Empty string is valid.
func IsDoesntStartWith ¶
IsDoesntStartWith check if the string does not start with any of the given prefixes. Empty string is valid.
func IsEmptyString ¶
IsEmptyString check if the string is empty.
func IsEndsWith ¶
IsEndsWith check if the string ends with any of the given suffixes. Empty string is valid.
func IsFloat64Between ¶
IsFloat64Between returns true if value lies between min and max (inclusive)
func IsFloat64Gt ¶
IsFloat64Gt returns true if value is greater than threshold
func IsFloat64Gte ¶
IsFloat64Gte returns true if value is greater than or equal to threshold
func IsFloat64Lt ¶
IsFloat64Lt returns true if value is less than threshold
func IsFloat64Lte ¶
IsFloat64Lte returns true if value is less than or equal to threshold
func IsGenericBetween ¶
func IsGenericBetween[T NumericType](value, min, max T) bool
IsGenericBetween checks if min <= value <= max.
func IsGenericDistinct ¶
func IsGenericDistinct[T comparable](value []T) bool
IsGenericDistinct checks if all slice elements are unique.
func IsGenericGt ¶
func IsGenericGt[T OrderedType](value, threshold T) bool
IsGenericGt checks if value > threshold.
func IsGenericGte ¶
func IsGenericGte[T OrderedType](value, threshold T) bool
IsGenericGte checks if value >= threshold.
func IsGenericIn ¶
func IsGenericIn[T comparable](value T, allowed []T) bool
IsGenericIn checks if value is in allowed list.
func IsGenericLt ¶
func IsGenericLt[T OrderedType](value, threshold T) bool
IsGenericLt checks if value < threshold.
func IsGenericLte ¶
func IsGenericLte[T OrderedType](value, threshold T) bool
IsGenericLte checks if value <= threshold.
func IsGenericMax ¶
func IsGenericMax[T NumericType](value, max T) bool
IsGenericMax checks if value <= max.
func IsGenericMin ¶
func IsGenericMin[T NumericType](value, min T) bool
IsGenericMin checks if value >= min.
func IsGenericNotIn ¶
func IsGenericNotIn[T comparable](value T, disallowed []T) bool
IsGenericNotIn checks if value is not in disallowed list.
func IsGenericRequired ¶
func IsGenericRequired[T comparable](value T) bool
IsGenericRequired checks if a comparable value is not zero.
func IsGenericRequiredMap ¶
func IsGenericRequiredMap[K comparable, V any](value map[K]V) bool
IsGenericRequiredMap checks if a map is not empty.
func IsGenericRequiredSlice ¶
IsGenericRequiredSlice checks if a slice is not empty.
func IsGt ¶
IsGt is the validation function for validating if the current field's value is greater than to the param's value.
func IsGtParam ¶
IsGtParam is the validation function for validating if the current field's value is greater than the param's value.
func IsGte ¶
IsGte is the validation function for validating if the current field's value is greater than to the param's value.
func IsGteParam ¶
IsGteParam is the validation function for validating if the current field's value is greater than or equal to the param's value.
func IsHexColor ¶
IsHexColor check if the string is a valid hex color code. Supports 3 and 6 character formats with or without # prefix. Examples: #fff, #FFF, #ffffff, #FFFFFF, fff, ffffff
func IsImage ¶
IsImage is the validation function for the The file under validation must be an image (jpeg, png, bmp, gif, or svg)
func IsInt64Between ¶
IsInt64Between returns true if value lies between min and max (inclusive)
func IsInt64Gte ¶
IsInt64Gte returns true if value is greater than or equal to threshold
func IsInt64Lte ¶
IsInt64Lte returns true if value is less than or equal to threshold
func IsLanguageAlpha2 ¶
IsLanguageAlpha2 validates ISO 639-1 language code (2-letter)
func IsLanguageAlpha3 ¶
IsLanguageAlpha3 validates ISO 639-2 language code (3-letter)
func IsLanguageCode ¶
IsLanguageCode validates any ISO 639 language code format
func IsLowercase ¶
IsLowercase check if the string is all lowercase. Empty string is valid.
func IsLt ¶
IsLt is the validation function for validating if the current field's value is less than the param's value.
func IsLtParam ¶
IsLtParam is the validation function for validating if the current field's value is less than the param's value.
func IsLte ¶
IsLte is the validation function for validating if the current field's value is less than or equal to the param's value.
func IsLteParam ¶
IsLteParam is the validation function for validating if the current field's value is less than or equal to the param's value.
func IsMACAddress ¶
IsMACAddress check if the string is a valid MAC address. Supports formats: XX:XX:XX:XX:XX:XX, XX-XX-XX-XX-XX-XX, XXXX.XXXX.XXXX Empty string is valid.
func IsMax ¶
IsMax is the validation function for validating if the current field's value is less than or equal to the param's value.
func IsMaxDigits ¶
IsMaxDigits is the validation function for validating the maximum number of digits.
func IsMimeTypes ¶
IsMimeTypes is the validation function for the file must match one of the given MIME types.
func IsMimes ¶
IsMimes is the validation function for the file must have a MIME type corresponding to one of the listed extensions.
func IsMin ¶
IsMin is the validation function for validating if the current field's value is greater than or equal to the param's value.
func IsMinDigits ¶
IsMinDigits is the validation function for validating the minimum number of digits.
func IsMultipleOf ¶
IsMultipleOf is the validation function for validating if a value is a multiple of another.
func IsNotRegex ¶
IsNotRegex checks if the value does not match the given regex pattern
func IsPhoneE164 ¶
IsPhoneE164 validates phone number in E.164 format (+[country code][number])
func IsPhoneMobile ¶
IsPhoneMobile validates if phone number is a mobile number
func IsPhoneValid ¶
IsPhoneValid validates phone number (any format, any region)
func IsProhibited ¶
func IsProhibited(i interface{}) bool
IsProhibited checks if the field is prohibited (must be empty)
func IsRequired ¶
func IsRequired(i interface{}) bool
IsRequired check value required when anotherField str is a member of the set of strings params
func IsRequiredArrayKeys ¶
IsRequiredArrayKeys checks if the map has all the specified keys
func IsSame ¶
IsSame is the validation function for validating if the current field's value is greater than or equal to the param's value.
func IsSize ¶
IsSize The field under validation must have a size matching the given value. For string data, value corresponds to the number of characters. For numeric data, value corresponds to a given integer value. For an array | map | slice, size corresponds to the count of the array | map | slice.
func IsStartsWith ¶
IsStartsWith check if the string starts with any of the given prefixes. Empty string is valid.
func IsStringBetween ¶
IsStringBetween checks if string length is between left and right
func IsTimezone ¶
IsTimezone check if the string is a valid timezone identifier. Uses Go's time.LoadLocation to validate. Examples: UTC, America/New_York, Europe/London, Asia/Tokyo
func IsULID ¶
IsULID check if the string is a valid ULID. ULID format: 01ARZ3NDEKTSV4RRFFQ69G5FAV (26 characters, Crockford's base32) Empty string is valid.
func IsUint64Between ¶
IsUint64Between returns true if value lies between min and max (inclusive)
func IsUint64Gt ¶
IsUint64Gt returns true if value is greater than threshold
func IsUint64Gte ¶
IsUint64Gte returns true if value is greater than or equal to threshold
func IsUint64Lt ¶
IsUint64Lt returns true if value is less than threshold
func IsUint64Lte ¶
IsUint64Lte returns true if value is less than or equal to threshold
func IsUppercase ¶
IsUppercase check if the string is all uppercase. Empty string is valid.
func ToInt ¶
ToInt convert the input string or any int type to an integer type 64, or 0 if the input is not an integer.
func ToString ¶
func ToString(obj interface{}) string
ToString convert the input to a string with optimized fast paths.
func ValidateStruct ¶
func ValidateStruct(s interface{}) error
ValidateStruct use tags for fields. result will be equal to `false` if there are any errors.
Types ¶
type CustomTypeValidateFunc ¶
CustomTypeValidateFunc is a wrapper for validator functions that returns bool. first parameter is field value second parameter is struct field third parameter is validTag message, pass the variable to the message
type DateRule ¶
type DateRule struct {
// contains filtered or unexported fields
}
IsDateRule provides fluent date validation building
func (*DateRule) AfterOrEqual ¶
AfterOrEqual adds an "after or equal" validation
func (*DateRule) BeforeOrEqual ¶
BeforeOrEqual adds a "before or equal" validation
func (*DateRule) BetweenOrEqual ¶
BetweenOrEqual adds a "between" validation (inclusive)
type DateValidator ¶
IsDateValidator represents a date validation function
type ErrorResponse ¶
type Errors ¶
type Errors []error
Errors is an array of multiple errors and conforms to the error interface.
func (Errors) FieldErrors ¶
func (es Errors) FieldErrors() []*FieldError
FieldErrors returns all FieldError instances
func (Errors) GetFieldError ¶
func (es Errors) GetFieldError(fieldName string) *FieldError
GetFieldError returns the first error for the specified field
func (Errors) GroupByField ¶
func (es Errors) GroupByField() map[string][]*FieldError
GroupByField groups errors by field name
func (Errors) HasFieldError ¶
HasFieldError checks if there's an error for the specified field
func (Errors) MarshalJSON ¶
MarshalJSON output Json format.
type FieldError ¶
type FieldError struct {
Name string `json:"name"`
StructName string `json:"struct_name,omitempty"`
Tag string `json:"tag"`
MessageName string `json:"message_name,omitempty"`
MessageParameters MessageParameters `json:"message_parameters,omitempty"`
Attribute string `json:"attribute,omitempty"`
DefaultAttribute string `json:"default_attribute,omitempty"`
Value string `json:"value,omitempty"`
Message string `json:"message"`
FuncError error `json:"func_error,omitempty"`
}
FieldError encapsulates name, message, and value etc.
func (*FieldError) Error ¶
func (fe *FieldError) Error() string
Error returns the error message with optional function error details
func (*FieldError) HasFuncError ¶
func (fe *FieldError) HasFuncError() bool
HasFuncError checks if there's an underlying function error
func (*FieldError) SetMessage ¶
func (fe *FieldError) SetMessage(msg string)
SetMessage sets the user-friendly message while preserving function error
func (*FieldError) Unwrap ¶
func (fe *FieldError) Unwrap() error
Unwrap implements the errors.Unwrap interface for error chain support
type IntegerType ¶
type IntegerType interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}
Type constraints for generics
type MessageParameters ¶
type MessageParameters []messageParameter
A MessageParameters represents store message parameter into field struct.
type NumericType ¶
type NumericType interface {
IntegerType | FloatType
}
Type constraints for generics
type OrderedType ¶
type OrderedType interface {
IntegerType | FloatType | ~string
}
Type constraints for generics
type ParamValidateFunc ¶
ParamValidateFunc is
type StringParamValidateFunc ¶
StringParamValidateFunc is
type TimeHelper ¶
TimeHelper wraps time.Time with helper methods
func (TimeHelper) AddDays ¶
func (t TimeHelper) AddDays(days int) time.Time
AddDays adds days to the time
func (TimeHelper) AddMonths ¶
func (t TimeHelper) AddMonths(months int) time.Time
AddMonths adds months to the time
func (TimeHelper) AddYears ¶
func (t TimeHelper) AddYears(years int) time.Time
AddYears adds years to the time
func (TimeHelper) SubDays ¶
func (t TimeHelper) SubDays(days int) time.Time
SubDays subtracts days from the time
type Translator ¶
type Translator struct {
// contains filtered or unexported fields
}
Translator type
func NewTranslator ¶
func NewTranslator() *Translator
NewTranslator returns a new instance of 'translator' with sane defaults.
func (*Translator) LoadMessage ¶
func (t *Translator) LoadMessage(langCode string) Translate
LoadMessage load message
func (*Translator) SetAttributes ¶
func (t *Translator) SetAttributes(langCode string, messages Translate)
SetAttributes set attributes
func (*Translator) SetMessage ¶
func (t *Translator) SetMessage(langCode string, messages Translate)
SetMessage set Message
type UnsupportedTypeError ¶
UnsupportedTypeError is a wrapper for reflect.Type
func (*UnsupportedTypeError) Error ¶
func (e *UnsupportedTypeError) Error() string
Error returns string equivalent for reflect.Type
type ValidTag ¶
type ValidTag struct {
// contains filtered or unexported fields
}
A ValidTag represents parse validTag into field struct.
type Validator ¶
type Validator struct {
Attributes map[string]string
CustomMessage map[string]string
Translator *Translator
}
Validator construct
func (*Validator) ValidateStruct ¶
ValidateStruct use tags for fields. result will be equal to `false` if there are any errors.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
_examples
|
|
|
custom
command
|
|
|
echo
command
|
|
|
gin
command
|
|
|
iris
command
|
|
|
simple
command
|
|
|
translation
command
|
|
|
translations
command
|
|
|
lang
|
|