Documentation ¶
Overview ¶
Package govalidator is package of validators and sanitizers for strings, structs and collections.
Index ¶
- Constants
- Variables
- func Abs(value float64) float64
- func BlackList(str, chars string) string
- func ByteLength(str string, params ...string) bool
- func CamelCaseToUnderscore(str string) string
- func Contains(str, substring string) bool
- func Count(array []interface{}, iterator ConditionIterator) int
- func Each(array []interface{}, iterator Iterator)
- func ErrorByField(e error, field string) string
- func ErrorsByField(e error) map[string]string
- func Filter(array []interface{}, iterator ConditionIterator) []interface{}
- func Find(array []interface{}, iterator ConditionIterator) interface{}
- func GetLine(s string, index int) (string, error)
- func GetLines(s string) []string
- func HasLowerCase(str string) bool
- func HasUpperCase(str string) bool
- func HasWhitespace(str string) bool
- func HasWhitespaceOnly(str string) bool
- func InRange(value interface{}, left interface{}, right interface{}) bool
- func InRangeFloat32(value, left, right float32) bool
- func InRangeFloat64(value, left, right float64) bool
- func InRangeInt(value, left, right interface{}) bool
- func IsASCII(str string) bool
- func IsAlpha(str string) bool
- func IsAlphanumeric(str string) bool
- func IsBase64(str string) bool
- func IsByteLength(str string, min, max int) bool
- func IsCIDR(str string) bool
- func IsCreditCard(str string) bool
- func IsDNSName(str string) bool
- func IsDataURI(str string) bool
- func IsDialString(str string) bool
- func IsDivisibleBy(str, num string) bool
- func IsEmail(str string) bool
- func IsExistingEmail(email string) bool
- func IsFilePath(str string) (bool, int)
- func IsFloat(str string) bool
- func IsFullWidth(str string) bool
- func IsHalfWidth(str string) bool
- func IsHash(str string, algorithm string) bool
- func IsHexadecimal(str string) bool
- func IsHexcolor(str string) bool
- func IsHost(str string) bool
- func IsIP(str string) bool
- func IsIPv4(str string) bool
- func IsIPv6(str string) bool
- func IsISBN(str string, version int) bool
- func IsISBN10(str string) bool
- func IsISBN13(str string) bool
- func IsISO3166Alpha2(str string) bool
- func IsISO3166Alpha3(str string) bool
- func IsISO4217(str string) bool
- func IsISO693Alpha2(str string) bool
- func IsISO693Alpha3b(str string) bool
- func IsIn(str string, params ...string) bool
- func IsInt(str string) bool
- func IsJSON(str string) bool
- func IsLatitude(str string) bool
- func IsLongitude(str string) bool
- func IsLowerCase(str string) bool
- func IsMAC(str string) bool
- func IsMongoID(str string) bool
- func IsMultibyte(str string) bool
- func IsNatural(value float64) bool
- func IsNegative(value float64) bool
- func IsNonNegative(value float64) bool
- func IsNonPositive(value float64) bool
- func IsNull(str string) bool
- func IsNumeric(str string) bool
- func IsPort(str string) bool
- func IsPositive(value float64) bool
- func IsPrintableASCII(str string) bool
- func IsRFC3339(str string) bool
- func IsRFC3339WithoutZone(str string) bool
- func IsRGBcolor(str string) bool
- func IsRequestURI(rawurl string) bool
- func IsRequestURL(rawurl string) bool
- func IsRsaPub(str string, params ...string) bool
- func IsRsaPublicKey(str string, keylen int) bool
- func IsSSN(str string) bool
- func IsSemver(str string) bool
- func IsTime(str string, format string) bool
- func IsURL(str string) bool
- func IsUTFDigit(str string) bool
- func IsUTFLetter(str string) bool
- func IsUTFLetterNumeric(str string) bool
- func IsUTFNumeric(str string) bool
- func IsUUID(str string) bool
- func IsUUIDv3(str string) bool
- func IsUUIDv4(str string) bool
- func IsUUIDv5(str string) bool
- func IsUpperCase(str string) bool
- func IsVariableWidth(str string) bool
- func IsWhole(value float64) bool
- func LeftTrim(str, chars string) string
- func Map(array []interface{}, iterator ResultIterator) []interface{}
- func Matches(str, pattern string) bool
- func NormalizeEmail(str string) (string, error)
- func PadBoth(str string, padStr string, padLen int) string
- func PadLeft(str string, padStr string, padLen int) string
- func PadRight(str string, padStr string, padLen int) string
- func PrependPathToErrors(err error, path string) error
- func Range(str string, params ...string) bool
- func RemoveTags(s string) string
- func ReplacePattern(str, pattern, replace string) string
- func Reverse(s string) string
- func RightTrim(str, chars string) string
- func RuneLength(str string, params ...string) bool
- func SafeFileName(str string) string
- func SetFieldsRequiredByDefault(value bool)
- func SetNilPtrAllowedByRequired(value bool)
- func Sign(value float64) float64
- func StringLength(str string, params ...string) bool
- func StringMatches(s string, params ...string) bool
- func StripLow(str string, keepNewLines bool) string
- func ToBoolean(str string) (bool, error)
- func ToFloat(str string) (float64, error)
- func ToInt(value interface{}) (res int64, err error)
- func ToJSON(obj interface{}) (string, error)
- func ToString(obj interface{}) string
- func Trim(str, chars string) string
- func Truncate(str string, length int, ending string) string
- func TruncatingErrorf(str string, args ...interface{}) error
- func UnderscoreToCamelCase(s string) string
- func ValidateStruct(s interface{}) (bool, error)
- func WhiteList(str, chars string) string
- type ConditionIterator
- type CustomTypeValidator
- type Error
- type Errors
- type ISO3166Entry
- type ISO693Entry
- type Iterator
- type ParamValidator
- type ResultIterator
- type UnsupportedTypeError
- type Validator
Constants ¶
const ( Email string = "" /* 1208-byte string literal not displayed */ CreditCard string = "" /* 151-byte string literal not displayed */ ISBN10 string = "^(?:[0-9]{9}X|[0-9]{10})$" ISBN13 string = "^(?:[0-9]{13})$" 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}$" Alpha string = "^[a-zA-Z]+$" Alphanumeric string = "^[a-zA-Z0-9]+$" Numeric string = "^[0-9]+$" 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 = "" /* 157-byte string literal not displayed */ ASCII string = "^[\x00-\x7F]+$" Multibyte string = "[^\x00-\x7F]" FullWidth string = "[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]" HalfWidth string = "[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]" Base64 string = "^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{4})$" PrintableASCII string = "^[\x20-\x7E]+$" DataURI string = "^data:.+\\/(.+);base64$" Latitude string = "^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)$" Longitude string = "^[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$" DNSName string = `^([a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62}){1}(\.[a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62})*[\._]?$` 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])(\.(1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.([0-9]\d?|1\d\d|2[0-4]\d|25[0-4]))` URLSubdomain string = `((www\.)|([a-zA-Z0-9]+([-_\.]?[a-zA-Z0-9])*[a-zA-Z0-9]\.[a-zA-Z0-9]+))` URL string = `^` + 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 + `?$` SSN string = `^\d{3}[- ]?\d{2}[- ]?\d{4}$` WinPath string = `^[a-zA-Z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*[^\\/:*?"<>|\r\n]*$` UnixPath string = `^(/[^/\x00]*)+/?$` Semver string = "" /* 183-byte string literal not displayed */ )
Basic regular expressions for validating strings
const ( // Unknown is unresolved OS type Unknown = iota // Win is Windows type Win // Unix is *nix OS types Unix )
Used by IsFilePath func
const RF3339WithoutZone = "2006-01-02T15:04:05"
Variables ¶
var CustomTypeTagMap = &customTypeTagMap{validators: make(map[string]CustomTypeValidator)}
CustomTypeTagMap is a map of functions that can be used as tags for ValidateStruct function. Use this to validate compound or custom types that need to be handled as a whole, e.g. `type UUID [16]byte` (this would be handled as an array of bytes).
var Escape = html.EscapeString
Escape replace <, >, & and " with HTML entities.
var ISO3166List = []ISO3166Entry{}/* 249 elements not displayed */
ISO3166List based on https://www.iso.org/obp/ui/#search/code/ Code Type "Officially Assigned Codes"
var ISO4217List = []string{}/* 178 elements not displayed */
ISO4217List is the list of ISO currency codes
var ISO693List = []ISO693Entry{}/* 184 elements not displayed */
ISO693List based on http://data.okfn.org/data/core/language-codes/r/language-codes-3b2.json
var ParamTagMap = map[string]ParamValidator{ "length": ByteLength, "range": Range, "runelength": RuneLength, "stringlength": StringLength, "matches": StringMatches, "in": isInRaw, "rsapub": IsRsaPub, }
ParamTagMap is a map of functions accept variants parameters
var ParamTagRegexMap = map[string]*regexp.Regexp{ "range": regexp.MustCompile("^range\\((\\d+)\\|(\\d+)\\)$"), "length": regexp.MustCompile("^length\\((\\d+)\\|(\\d+)\\)$"), "runelength": regexp.MustCompile("^runelength\\((\\d+)\\|(\\d+)\\)$"), "stringlength": regexp.MustCompile("^stringlength\\((\\d+)\\|(\\d+)\\)$"), "in": regexp.MustCompile(`^in\((.*)\)`), "matches": regexp.MustCompile(`^matches\((.+)\)$`), "rsapub": regexp.MustCompile("^rsapub\\((\\d+)\\)$"), }
ParamTagRegexMap maps param tags to their respective regexes.
var TagMap = map[string]Validator{ "email": IsEmail, "url": IsURL, "dialstring": IsDialString, "requrl": IsRequestURL, "requri": IsRequestURI, "alpha": IsAlpha, "utfletter": IsUTFLetter, "alphanum": IsAlphanumeric, "utfletternum": IsUTFLetterNumeric, "numeric": IsNumeric, "utfnumeric": IsUTFNumeric, "utfdigit": IsUTFDigit, "hexadecimal": IsHexadecimal, "hexcolor": IsHexcolor, "rgbcolor": IsRGBcolor, "lowercase": IsLowerCase, "uppercase": IsUpperCase, "int": IsInt, "float": IsFloat, "null": IsNull, "uuid": IsUUID, "uuidv3": IsUUIDv3, "uuidv4": IsUUIDv4, "uuidv5": IsUUIDv5, "creditcard": IsCreditCard, "isbn10": IsISBN10, "isbn13": IsISBN13, "json": IsJSON, "multibyte": IsMultibyte, "ascii": IsASCII, "printableascii": IsPrintableASCII, "fullwidth": IsFullWidth, "halfwidth": IsHalfWidth, "variablewidth": IsVariableWidth, "base64": IsBase64, "datauri": IsDataURI, "ip": IsIP, "port": IsPort, "ipv4": IsIPv4, "ipv6": IsIPv6, "dns": IsDNSName, "host": IsHost, "mac": IsMAC, "latitude": IsLatitude, "longitude": IsLongitude, "ssn": IsSSN, "semver": IsSemver, "rfc3339": IsRFC3339, "rfc3339WithoutZone": IsRFC3339WithoutZone, "ISO3166Alpha2": IsISO3166Alpha2, "ISO3166Alpha3": IsISO3166Alpha3, "ISO4217": IsISO4217, }
TagMap is a map of functions, that can be used as tags for ValidateStruct function.
Functions ¶
func BlackList ¶
BlackList remove characters that appear in the blacklist.
func ByteLength ¶
ByteLength check string's length
func CamelCaseToUnderscore ¶
CamelCaseToUnderscore converts from camel case form to underscore separated form. Ex.: MyFunc => my_func
func Contains ¶
Contains check if the string contains the substring.
func Count ¶
func Count(array []interface{}, iterator ConditionIterator) int
Count iterates over the slice and apply ConditionIterator to every item. Returns count of items that meets ConditionIterator.
func Each ¶
func Each(array []interface{}, iterator Iterator)
Each iterates over the slice and apply Iterator to every item
func ErrorByField ¶
ErrorByField returns error for specified field of the struct validated by ValidateStruct or empty string if there are no errors or this field doesn't exists or doesn't have any errors.
func ErrorsByField ¶
ErrorsByField returns map of errors of the struct validated by ValidateStruct or empty map if there are no errors.
func Filter ¶
func Filter(array []interface{}, iterator ConditionIterator) []interface{}
Filter iterates over the slice and apply ConditionIterator to every item. Returns new slice.
func Find ¶
func Find(array []interface{}, iterator ConditionIterator) interface{}
Find iterates over the slice and apply ConditionIterator to every item. Returns first item that meet ConditionIterator or nil otherwise.
func GetLine ¶
GetLine return specified line of multiline string
func GetLines ¶
GetLines split string by "\n" and return array of lines
func HasLowerCase ¶
HasLowerCase check if the string contains at least 1 lowercase. Empty string is valid.
func HasUpperCase ¶
HasUpperCase check if the string contians as least 1 uppercase. Empty string is valid.
func HasWhitespace ¶
HasWhitespace checks if the string contains any whitespace
func HasWhitespaceOnly ¶
HasWhitespaceOnly checks the string only contains whitespace
func InRange ¶
func InRange(value interface{}, left interface{}, right interface{}) bool
InRange returns true if value lies between left and right border, generic type to handle int, float32 or float64, all types must the same type
func InRangeFloat32 ¶
InRange returns true if value lies between left and right border
func InRangeFloat64 ¶
InRange returns true if value lies between left and right border
func InRangeInt ¶
func InRangeInt(value, left, right interface{}) bool
InRange returns true if value lies between left and right border
func IsASCII ¶
IsASCII check if the string contains ASCII chars only. Empty string is valid.
func IsAlpha ¶
IsAlpha check if the string contains only letters (a-zA-Z). Empty string is valid.
func IsAlphanumeric ¶
IsAlphanumeric check if the string contains only letters and numbers. Empty string is valid.
func IsByteLength ¶
IsByteLength check if the string's length (in bytes) falls in a range.
func IsCIDR ¶
IsCIDR check if the string is an valid CIDR notiation (IPV4 & IPV6)
func IsCreditCard ¶
IsCreditCard check if the string is a credit card.
func IsDNSName ¶
IsDNSName will validate the given string as a DNS name
func IsDataURI ¶
IsDataURI checks if a string is base64 encoded data URI such as an image
func IsDialString ¶
IsDialString validates the given string for usage with the various Dial() functions
func IsDivisibleBy ¶
IsDivisibleBy check if the string is a number that's divisible by another. If second argument is not valid integer or zero, it's return false. Otherwise, if first argument is not valid integer or zero, it's return true (Invalid string converts to zero).
func IsExistingEmail ¶
IsExistingEmail check if the string is an email of existing domain
func IsFilePath ¶
IsFilePath check is a string is Win or Unix file path and returns it's type.
func IsFullWidth ¶
IsFullWidth check if the string contains any full-width chars. Empty string is valid.
func IsHalfWidth ¶
IsHalfWidth check if the string contains any half-width chars. Empty string is valid.
func IsHash ¶
IsHash checks if a string is a hash of type algorithm. Algorithm is one of ['md4', 'md5', 'sha1', 'sha256', 'sha384', 'sha512', 'ripemd128', 'ripemd160', 'tiger128', 'tiger160', 'tiger192', 'crc32', 'crc32b']
func IsHexadecimal ¶
IsHexadecimal check if the string is a hexadecimal number.
func IsHexcolor ¶
IsHexcolor check if the string is a hexadecimal color.
func IsHost ¶
IsHost checks if the string is a valid IP (both v4 and v6) or a valid DNS name
func IsISBN ¶
IsISBN check if the string is an ISBN (version 10 or 13). If version value is not equal to 10 or 13, it will be check both variants.
func IsISO3166Alpha2 ¶
IsISO3166Alpha2 checks if a string is valid two-letter country code
func IsISO3166Alpha3 ¶
IsISO3166Alpha3 checks if a string is valid three-letter country code
func IsISO4217 ¶
IsISO4217 check if string is valid ISO currency code
func IsISO693Alpha2 ¶
IsISO693Alpha2 checks if a string is valid two-letter language code
func IsISO693Alpha3b ¶
IsISO693Alpha3b checks if a string is valid three-letter language code
func IsIn ¶
IsIn check if string str is a member of the set of strings params
func IsInt ¶
IsInt check if the string is an integer. Empty string is valid.
func IsJSON ¶
IsJSON check if the string is valid JSON (note: uses json.Unmarshal).
func IsLongitude ¶
IsLongitude check if a string is valid longitude.
func IsLowerCase ¶
IsLowerCase check if the string is lowercase. Empty string is valid.
func IsMAC ¶
IsMAC check if a string is valid MAC address. Possible MAC formats: 01:23:45:67:89:ab 01:23:45:67:89:ab:cd:ef 01-23-45-67-89-ab 01-23-45-67-89-ab-cd-ef 0123.4567.89ab 0123.4567.89ab.cdef
func IsMongoID ¶
IsMongoID check if the string is a valid hex-encoded representation of a MongoDB ObjectId.
func IsMultibyte ¶
IsMultibyte check if the string contains one or more multibyte chars. Empty string is valid.
func IsNatural ¶
IsNatural returns true if value is natural number (positive and whole)
func IsNonNegative ¶
IsNonNegative returns true if value >= 0
func IsNonPositive ¶
IsNonPositive returns true if value <= 0
func IsNumeric ¶
IsNumeric check if the string contains only numbers. Empty string is valid.
func IsPrintableASCII ¶
IsPrintableASCII check if the string contains printable ASCII chars only. Empty string is valid.
func IsRFC3339 ¶
IsRFC3339 check if string is valid timestamp value according to RFC3339
func IsRFC3339WithoutZone ¶
IsRFC3339WithoutZone check if string is valid timestamp value according to RFC3339 which excludes the timezone.
func IsRGBcolor ¶
IsRGBcolor check if the string is a valid RGB color in form rgb(RRR, GGG, BBB).
func IsRequestURI ¶
IsRequestURI check if the string rawurl, assuming it was received in an HTTP request, is an absolute URI or an absolute path.
func IsRequestURL ¶
IsRequestURL check if the string rawurl, assuming it was received in an HTTP request, is a valid URL confirm to RFC 3986
func IsRsaPub ¶
IsRsaPub check whether string is valid RSA key Alias for IsRsaPublicKey
func IsRsaPublicKey ¶
IsRsaPublicKey check if a string is valid public key with provided length
func IsSSN ¶
IsSSN will validate the given string as a U.S. Social Security Number
func IsTime ¶
IsTime check if string is valid according to given format
func IsUTFDigit ¶
IsUTFDigit check if the string contains only unicode radix-10 decimal digits. Empty string is valid.
func IsUTFLetter ¶
IsUTFLetter check if the string contains only unicode letter characters. Similar to IsAlpha but for all languages. Empty string is valid.
func IsUTFLetterNumeric ¶
IsUTFLetterNumeric check if the string contains only unicode letters and numbers. Empty string is valid.
func IsUTFNumeric ¶
IsUTFNumeric check if the string contains only unicode numbers of any kind. Numbers can be 0-9 but also Fractions ¾,Roman Ⅸ and Hangzhou 〩. Empty string is valid.
func IsUUID ¶
IsUUID check if the string is a UUID (version 3, 4 or 5).
func IsUpperCase ¶
IsUpperCase check if the string is uppercase. Empty string is valid.
func IsVariableWidth ¶
IsVariableWidth check if the string contains a mixture of full and half-width chars. Empty string is valid.
func LeftTrim ¶
LeftTrim trim characters from the left-side of the input. If second argument is empty, it's will be remove leading spaces.
func Map ¶
func Map(array []interface{}, iterator ResultIterator) []interface{}
Map iterates over the slice and apply ResultIterator to every item. Returns new slice as a result.
func Matches ¶
Matches check if string matches the pattern (pattern is regular expression) In case of error return false
func NormalizeEmail ¶
NormalizeEmail canonicalize an email address. The local part of the email address is lowercased for all domains; the hostname is always lowercased and the local part of the email address is always lowercased for hosts that are known to be case-insensitive (currently only GMail). Normalization follows special rules for known providers: currently, GMail addresses have dots removed in the local part and are stripped of tags (e.g. some.one+tag@gmail.com becomes someone@gmail.com) and all @googlemail.com addresses are normalized to @gmail.com.
func PadBoth ¶
PadBoth pad sides of string if size of string is less then indicated pad length
func PadLeft ¶
PadLeft pad left side of string if size of string is less then indicated pad length
func PadRight ¶
PadRight pad right side of string if size of string is less then indicated pad length
func ReplacePattern ¶
ReplacePattern replace regular expression pattern in string
func RightTrim ¶
RightTrim trim characters from the right-side of the input. If second argument is empty, it's will be remove spaces.
func RuneLength ¶
RuneLength check string's length Alias for StringLength
func SafeFileName ¶
SafeFileName return safe string that can be used in file names
func SetFieldsRequiredByDefault ¶
func SetFieldsRequiredByDefault(value bool)
SetFieldsRequiredByDefault causes validation to fail when struct fields do not include validations or are not explicitly marked as exempt (using `valid:"-"` or `valid:"email,optional"`). This struct definition will fail govalidator.ValidateStruct() (and the field values do not matter):
type exampleStruct struct { Name string `` Email string `valid:"email"`
This, however, will only fail when Email is empty or an invalid email address:
type exampleStruct2 struct { Name string `valid:"-"` Email string `valid:"email"`
Lastly, this will only fail when Email is an invalid email address but not when it's empty:
type exampleStruct2 struct { Name string `valid:"-"` Email string `valid:"email,optional"`
func SetNilPtrAllowedByRequired ¶
func SetNilPtrAllowedByRequired(value bool)
SetNilPtrAllowedByRequired causes validation to pass for nil ptrs when a field is set to required. The validation will still reject ptr fields in their zero value state. Example with this enabled:
type exampleStruct struct { Name *string `valid:"required"`
With `Name` set to "", this will be considered invalid input and will cause a validation error. With `Name` set to nil, this will be considered valid by validation. By default this is disabled.
func Sign ¶
Sign returns signum of number: 1 in case of value > 0, -1 in case of value < 0, 0 otherwise
func StringLength ¶
StringLength check string's length (including multi byte strings)
func StringMatches ¶
StringMatches checks if a string matches a given pattern.
func StripLow ¶
StripLow remove characters with a numerical value < 32 and 127, mostly control characters. If keep_new_lines is true, newline characters are preserved (\n and \r, hex 0xA and 0xD).
func ToBoolean ¶
ToBoolean convert the input string to a boolean.
func ToFloat ¶
ToFloat convert the input string to a float, or 0.0 if the input is not a float.
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 ToJSON ¶
ToJSON convert the input to a valid JSON string
func Trim ¶
Trim trim characters from both sides of the input. If second argument is empty, it's will be remove spaces.
func Truncate ¶
Truncate a string to the closest length without breaking words.
func TruncatingErrorf ¶
TruncatingErrorf removes extra args from fmt.Errorf if not formatted in the str object
func UnderscoreToCamelCase ¶
UnderscoreToCamelCase converts from underscore separated form to camel case form. Ex.: my_func => MyFunc
func ValidateStruct ¶
ValidateStruct use tags for fields. result will be equal to `false` if there are any errors.
Types ¶
type ConditionIterator ¶
ConditionIterator is the function that accepts element of slice/array and its index and returns boolean
type CustomTypeValidator ¶
type CustomTypeValidator func(i interface{}, o interface{}) bool
CustomTypeValidator is a wrapper for validator functions that returns bool and accepts any type. The second parameter should be the context (in the case of validating a struct: the whole object being validated).
type Error ¶
type Error struct { Name string Err error CustomErrorMessageExists bool // Validator indicates the name of the validator that failed Validator string Path []string }
Error encapsulates a name, an error and whether there's a custom error message or not.
type Errors ¶
type Errors []error
Errors is an array of multiple errors and conforms to the error interface.
type ISO3166Entry ¶
type ISO3166Entry struct { EnglishShortName string FrenchShortName string Alpha2Code string Alpha3Code string Numeric string }
ISO3166Entry stores country codes
type ISO693Entry ¶
ISO693Entry stores ISO language codes
type Iterator ¶
type Iterator func(interface{}, int)
Iterator is the function that accepts element of slice/array and its index
type ParamValidator ¶
ParamValidator is a wrapper for validator functions that accepts additional parameters.
type ResultIterator ¶
type ResultIterator func(interface{}, int) interface{}
ResultIterator is the function that accepts element of slice/array and its index and returns any result
type UnsupportedTypeError ¶
UnsupportedTypeError is a wrapper for reflect.Type
func (*UnsupportedTypeError) Error ¶
func (e *UnsupportedTypeError) Error() string
Error returns string equivalent for reflect.Type