Documentation
¶
Index ¶
- Constants
- Variables
- func FloatIsGreaterThan[T float64](value T, min T) bool
- func FloatIsGreaterThanOrEqualTo[T float64](value T, min T) bool
- func FloatIsInRange[T float64](value T, min T, max T) bool
- func FloatIsLessThan[T float64](value T, max T) bool
- func FloatIsLessThanOrEqualTo[T float64](value T, max T) bool
- func FloatIsMultipleOf[T float64](value T, multiple T) bool
- func FloatIsNegative[T float64](value T) bool
- func FloatIsNonZero[T float64](value T) bool
- func FloatIsPositive[T float64](value T) bool
- func FloatIsZero[T float64](value T) bool
- func IsBCP47LanguageTag(str string) error
- func IsBIC(str string) error
- func IsBTCAddress(str string) error
- func IsBase64(str string) error
- func IsBase64RawURL(str string) error
- func IsBase64URL(str string) error
- func IsDivisibleBy[T int](value T, divisor T) bool
- func IsEthAddress(s string) bool
- func IsEven[T int](value T) bool
- func IsGreaterThan[T int](value T, min T) bool
- func IsGreaterThanOrEqualTo[T int](value T, min T) bool
- func IsInRange[T int](value T, min T, max T) bool
- func IsLessThan[T int](value T, max T) bool
- func IsLessThanOrEqualTo[T int](value T, max T) bool
- func IsMultipleOf[T int](value T, multiple T) bool
- func IsNegative[T int](value T) bool
- func IsNonZero[T int](value T) bool
- func IsOdd[T int](value T) bool
- func IsValidCreditCard(str string) error
- func IsValidCron(str string) error
- func IsValidDatetime(str string) error
- func IsValidE164PhoneNumber(str string) error
- func IsValidEmail(str string) error
- func IsValidMongoID(str string) error
- func IsZero[T int](value T) bool
- func SliceIsPresent(value []interface{}) bool
- func SliceIsUnique[T comparable](value []T, f func(T) interface{}) bool
- func StringContains(s, substr string) error
- func StringContainsAny(s string, substrs ...string) error
- func StringContainsRune(s string, r rune) error
- func StringEndsNotWith(s, substr string) error
- func StringEndsWith(s, substr string) error
- func StringExcludes(s, substr string) error
- func StringExcludesAll(s string, substrs ...string) error
- func StringExcludesRune(s string, r rune) error
- func StringIsASCIICode(s string) error
- func StringIsAlpha(s string) error
- func StringIsAlphaUnicode(s string) error
- func StringIsAlphanumeric(s string) error
- func StringIsAlphanumericUnicode(s string) error
- func StringIsBoolean(s string) error
- func StringIsLowerCase(s string) error
- func StringIsMultibyte(s string) error
- func StringIsNumeric(s string) error
- func StringIsPrintableASCII(s string) error
- func StringIsUpperCase(s string) error
- func StringStartsNotWith(s, substr string) error
- func StringStartsWith(s, substr string) error
- func ValidateCIDRv4(cidr string) error
- func ValidateCIDRv6(cidr string) error
- func ValidateDataURL(dataURL string) error
- func ValidateFQDN(fqdn string) error
- func ValidateHTTPURL(urlStr string) error
- func ValidateHostname(hostname string) error
- func ValidateIPAddress(ipAddress string) error
- func ValidateIPv4Address(ipAddress string) error
- func ValidateIPv6Address(ipAddress string) error
- func ValidateMACAddress(macAddress string) error
- func ValidateRFC952(hostname string) error
- func ValidateTCP4Addr(addr string) error
- func ValidateTCP6Addr(addr string) error
- func ValidateTCPAddr(addr string) error
- func ValidateUDP4Addr(addr string) error
- func ValidateUDP6Addr(addr string) error
- func ValidateUDPAddr(addr string) error
- func ValidateURI(uri string) error
- func ValidateURL(urlStr string) error
- func ValidateURLEncoded(data string) error
- func ValidateURNRFC2141(urn string) error
- func ValidateUnixAddr(addr string) error
Constants ¶
const (
AddressLength = 20
)
Variables ¶
var ( ErrInvalidBase64 = errors.New("invalid base64 encoding") ErrInvalidBase64URL = errors.New("invalid base64url encoding") ErrInvalidBase64RawURL = errors.New("invalid base64rawurl encoding") ErrInvalidBIC = errors.New("invalid BIC") ErrInvalidBCP47LanguageTag = errors.New("invalid BCP47 language tag") // ErrInvalidCreditCard is returned when the provided credit card number is invalid ErrInvalidCreditCard = errors.New("invalid credit card number") // ErrInvalidMongoID is returned when the provided string is not a valid MongoDB object ID. ErrInvalidMongoID = errors.New("invalid MongoDB object ID") ErrInvalidCron = errors.New("invalid CRON expression") ErrInvalidDatetime = errors.New("invalid Datetime") ErrInvalidE164PhoneNumber = errors.New("invalid E.164 phone number") ErrInvalidEmail = errors.New("invalid email address") )
var ( // ErrEmptyIPAddress is returned when IP address is empty. ErrEmptyIPAddress = errors.New("IP address cannot be empty") // ErrInvalidIPAddress is returned when IP address is invalid. ErrInvalidIPAddress = errors.New("invalid IP address") // ErrEmptyHostname is returned when hostname is empty. ErrEmptyHostname = errors.New("hostname cannot be empty") // ErrHostnameTooLong is returned when hostname is too long. ErrHostnameTooLong = errors.New("hostname is too long") // ErrInvalidHostname is returned when hostname is invalid. ErrInvalidHostname = errors.New("invalid hostname") // ErrInvalidIPv6Address is returned when IPv6 address is invalid. ErrInvalidIPv6Address = errors.New("invalid IPv6 address") // ErrExpectedIPv6Address is returned when IPv6 address is expected. ErrExpectedIPv6Address = errors.New("IPv6 address expected") // ErrInvalidIPv4Address is returned when IPv4 address is invalid. ErrInvalidIPv4Address = errors.New("invalid IPv4 address") // ErrExpectedIPv4Address is returned when IPv4 address is expected. ErrExpectedIPv4Address = errors.New("IPv4 address expected") // ErrEmptyMACAddress is returned when MAC address is empty. ErrEmptyMACAddress = errors.New("MAC address cannot be empty") // ErrInvalidMACAddress is returned when MAC address is invalid. ErrInvalidMACAddress = errors.New("invalid MAC address") // ErrEmptyURL is returned when URL is empty. ErrEmptyURL = errors.New("URL cannot be empty") // ErrInvalidURL is returned when URL is invalid. ErrInvalidURL = errors.New("invalid URL") // ErrInvalidCIDRv4 is returned when a CIDRv4 address is invalid. ErrInvalidCIDRv4 = errors.New("invalid CIDRv4 address") // ErrInvalidCIDRv6 is returned when a CIDRv6 address is invalid. ErrInvalidCIDRv6 = errors.New("invalid CIDRv6 address") // ErrInvalidDataURL is returned when a data URL is invalid. ErrInvalidDataURL = errors.New("invalid data URL") // ErrInvalidFQDN is returned when a fully qualified domain name is invalid. ErrInvalidFQDN = errors.New("invalid FQDN") // ErrInvalidRFC952Hostname is returned when an RFC 952 hostname is invalid. ErrInvalidRFC952Hostname = errors.New("invalid RFC 952 hostname") // ErrInvalidTCP4Addr is returned when ValidateTCP4Addr is given an invalid TCPv4 address. ErrInvalidTCP4Addr = errors.New("invalid TCPv4 address") // ErrInvalidTCP6Addr is returned when ValidateTCP6Addr is given an invalid TCPv6 address. ErrInvalidTCP6Addr = errors.New("invalid TCPv6 address") // ErrInvalidTCPAddr is returned when ValidateTCPAddr is given an invalid TCP address. ErrInvalidTCPAddr = errors.New("invalid TCP address") // ErrInvalidUDP4Addr is returned when ValidateUDP4Addr is given an invalid UDPv4 address. ErrInvalidUDP4Addr = errors.New("invalid UDPv4 address") // ErrInvalidUDP6Addr is returned when ValidateUDP6Addr is given an invalid UDPv6 address. ErrInvalidUDP6Addr = errors.New("invalid UDPv6 address") // ErrInvalidUDPAddr is returned when ValidateUDPAddr is given an invalid UDP address. ErrInvalidUDPAddr = errors.New("invalid UDP address") // ErrInvalidUnixAddr is returned when ValidateUnixAddr is given an invalid Unix domain socket address. ErrInvalidUnixAddr = errors.New("invalid Unix domain socket address") // ErrInvalidURI is returned when ValidateURI is given an invalid URI. ErrInvalidURI = errors.New("invalid URI") // ErrInvalidHTTPURL is returned when ValidateHTTPURL is given an invalid HTTP or HTTPS URL. ErrInvalidHTTPURL = errors.New("invalid HTTP or HTTPS URL") // ErrInvalidURLEncoded is returned when ValidateURLEncoded is given invalid URL-encoded data. ErrInvalidURLEncoded = errors.New("invalid URL-encoded data") // ErrInvalidURNRFC2141 is returned when ValidateURNRFC2141 is given an invalid URN according to RFC 2141. ErrInvalidURNRFC2141 = errors.New("invalid URN according to RFC 2141") )
var ( ErrNotAlpha = errors.New("string is not alpha") ErrNotAlphanumeric = errors.New("string is not alphanumeric") ErrNotAlphanumericUnicode = errors.New("string is not alphanumeric unicode") ErrNotAlphaUnicode = errors.New("string is not alpha unicode") ErrNotASCIICode = errors.New("string is not ASCII code") ErrNotBoolean = errors.New("string is not a boolean") ErrDoesNotContain = errors.New("string does not contain the substring") ErrDoesNotContainAny = errors.New("string does not contain any of the substrings") ErrDoesNotContainRune = errors.New("string does not contain the rune") ErrEndsWith = errors.New("string ends with the substring") ErrEndsNotWith = errors.New("string does not end with the substring") ErrExcludes = errors.New("string includes the substring") ErrExcludesAll = errors.New("string does not include all of the substrings") ErrIncludesAll = errors.New("string does not include all of the substrings") ErrExcludesRune = errors.New("string includes the rune") ErrNotLowerCase = errors.New("string is not lowercase") ErrNotUpercase = errors.New("string is not uppercase") ErrNotMultibyte = errors.New("string does not contain one or more multibyte characters") ErrNotNumeric = errors.New("string is not numeric") ErrNotPrintableASCII = errors.New("string contains non-printable ASCII characters") ErrStartsWith = errors.New("string starts with the substring") ErrNotStartsWith = errors.New("string does not start with the substring") )
Functions ¶
func FloatIsGreaterThan ¶
func FloatIsInRange ¶
func FloatIsLessThan ¶
func FloatIsMultipleOf ¶
func FloatIsNegative ¶
func FloatIsNonZero ¶
func FloatIsPositive ¶
func FloatIsZero ¶
func IsBCP47LanguageTag ¶
IsBCP47LanguageTag checks if the given string is a valid BCP47 language tag.
func IsBTCAddress ¶
IsBTCAddress checks if the given string is a valid Bitcoin address.
func IsBase64RawURL ¶
IsBase64RawURL checks if the given string is a valid base64rawurl encoding.
func IsBase64URL ¶
IsBase64URL checks if the given string is a valid base64url encoding.
func IsDivisibleBy ¶
func IsEthAddress ¶
IsEthAddress checks if the given string is a valid etherum address
func IsGreaterThan ¶
func IsGreaterThanOrEqualTo ¶
func IsLessThan ¶
func IsLessThanOrEqualTo ¶
func IsMultipleOf ¶
func IsNegative ¶
func IsValidCreditCard ¶
func IsValidCron ¶
IsValidCron checks if the given string is a valid CRON expression.
func IsValidDatetime ¶
IsValidDatetime checks if the given string is a valid datetime in the format of "YYYY-MM-DD HH:MM:SS".
func IsValidE164PhoneNumber ¶
IsValidE164PhoneNumber checks if the given string is a valid E.164 phone number.
func IsValidEmail ¶
IsValidEmail checks if the given string is a valid email address.
func IsValidMongoID ¶
IsValidMongoID checks if the given string is a valid MongoDB object ID.
func SliceIsPresent ¶
func SliceIsPresent(value []interface{}) bool
func SliceIsUnique ¶
func SliceIsUnique[T comparable](value []T, f func(T) interface{}) bool
SliceIsUnique checks if all elements in a slice are unique by applying a function to each element and comparing the result.
Example:
SliceIsUnique([]string{"a", "b", "c"}, func(s string) interface{} { return s })
SliceIsUnique([]int{1, 2, 3}, func(i int) interface{} { return i })
SliceIsUnique([]struct{ A, B int }{{1, 2}, {3, 4}, {5, 6}}, func(s struct{ A, B int }) interface{} { return s.A })
Note: The function f must return a comparable type. See https://golang.org/ref/spec#Comparison_operators
func StringContains ¶
StringContains checks if a string contains a substring.
func StringContainsAny ¶
StringContainsAny checks if a string contains any of the substrings.
func StringContainsRune ¶
StringContainsRune checks if a string contains a rune.
func StringEndsNotWith ¶
StringEndsNotWith checks if a string does not end with a substring.
func StringEndsWith ¶
StringEndsWith checks if a string ends with a substring.
func StringExcludes ¶
StringExcludes checks if a string excludes a substring.
func StringExcludesAll ¶
StringExcludesAll checks if a string excludes all of the substrings.
func StringExcludesRune ¶
StringExcludesRune checks if a string excludes a rune.
func StringIsASCIICode ¶
StringIsASCIICode checks if a string contains only ASCII characters.
func StringIsAlpha ¶
StringIsAlpha checks if a string contains only letters.
func StringIsAlphaUnicode ¶
StringIsAlphaUnicode checks if a string contains only unicode letters.
func StringIsAlphanumeric ¶
StringIsAlphanumeric checks if a string contains only numbers.
func StringIsAlphanumericUnicode ¶
StringIsAlphaUnicode checks if a string contains only unicode letters.
func StringIsBoolean ¶
StringIsBoolean checks if a string is a boolean.
func StringIsLowerCase ¶
StringIsLowerCase checks if a string is lowercase.
func StringIsMultibyte ¶
StringIsMultibyte checks if a string contains one or more multibyte characters.
func StringIsNumeric ¶
StringIsNumeric checks if a string contains only numbers.
func StringIsPrintableASCII ¶
StringIsPrintableASCII checks if a string contains only printable ASCII characters.
func StringIsUpperCase ¶
StringIsUpperCase checks if a string is uppercase.
func StringStartsNotWith ¶
StringStartsNotWith checks if a string does not start with a substring.
func StringStartsWith ¶
StringStartsWith checks if a string starts with a substring.
func ValidateCIDRv4 ¶
ValidateCIDRv4 validates a CIDRv4 address.
func ValidateCIDRv6 ¶
ValidateCIDRv6 validates a CIDRv6 address.
func ValidateDataURL ¶
ValidateDataURL validates a data URL.
func ValidateFQDN ¶
ValidateFQDN validates a fully qualified domain name.
func ValidateHTTPURL ¶
ValidateHTTPURL checks if the given string is a valid HTTP or HTTPS URL.
func ValidateHostname ¶
ValidateHostname validates a hostname.
func ValidateIPAddress ¶
ValidateIPAddress validates an IPv4 or IPv6 address.
func ValidateIPv4Address ¶
ValidateIPv4Address validates an IPv4 address.
func ValidateIPv6Address ¶
ValidateIPv6Address validates an IPv6 address.
func ValidateMACAddress ¶
ValidateMACAddress validates a MAC address.
func ValidateRFC952 ¶
ValidateRFC952 validates an RFC 952 hostname.
func ValidateTCP4Addr ¶
ValidateTCP4Addr checks if the given address is a valid TCPv4 address.
func ValidateTCP6Addr ¶
ValidateTCP6Addr checks if the given address is a valid TCPv6 address.
func ValidateTCPAddr ¶
ValidateTCPAddr checks if the given address is a valid TCP address.
func ValidateUDP4Addr ¶
ValidateUDP4Addr checks if the given address is a valid UDPv4 address.
func ValidateUDP6Addr ¶
ValidateUDP6Addr checks if the given address is a valid UDPv6 address.
func ValidateUDPAddr ¶
ValidateUDPAddr checks if the given address is a valid UDP address.
func ValidateURI ¶
ValidateURI checks if the given string is a valid URI.
func ValidateURL ¶
ValidateURL checks if the given string is a valid URL.
func ValidateURLEncoded ¶
ValidateURLEncoded checks if the given string is valid URL-encoded data.
func ValidateURNRFC2141 ¶
ValidateURNRFC2141 checks if the given string is a valid URN according to RFC 2141.
func ValidateUnixAddr ¶
ValidateUnixAddr checks if the given address is a valid Unix domain socket address.
Types ¶
This section is empty.