Documentation ¶
Overview ¶
Package checker is a Go library for validating user input through struct tags.
Index ¶
- Constants
- func FailIfNoPanic(t *testing.T)
- func Register(name string, maker MakeFunc)
- type CheckFunc
- type MakeFunc
- type Mistakes
- type Result
- func IsASCII(value string) Result
- func IsAlphanumeric(value string) Result
- func IsAmexCreditCard(number string) Result
- func IsAnyCreditCard(number string) Result
- func IsCidr(value string) Result
- func IsDigits(value string) Result
- func IsDinersCreditCard(number string) Result
- func IsDiscoveryCreditCard(number string) Result
- func IsEmail(email string) Result
- func IsFqdn(domain string) Result
- func IsIP(value string) Result
- func IsIPV4(value string) Result
- func IsIPV6(value string) Result
- func IsISBN(value string) Result
- func IsISBN10(value string) Result
- func IsISBN13(value string) Result
- func IsJcbCreditCard(number string) Result
- func IsLuhn(number string) Result
- func IsMac(value string) Result
- func IsMasterCardCreditCard(number string) Result
- func IsMax(value interface{}, max float64) Result
- func IsMaxLength(value interface{}, maxLength int) Result
- func IsMin(value interface{}, min float64) Result
- func IsMinLength(value interface{}, minLength int) Result
- func IsRequired(v interface{}) Result
- func IsURL(value string) Result
- func IsUnionPayCreditCard(number string) Result
- func IsVisaCreditCard(number string) Result
Constants ¶
const CheckerASCII = "ascii"
CheckerASCII is the name of the checker.
const CheckerAlphanumeric = "alphanumeric"
CheckerAlphanumeric is the name of the checker.
const CheckerCidr = "cidr"
CheckerCidr is the name of the checker.
const CheckerCreditCard = "credit-card"
CheckerCreditCard is the name of the checker.
const CheckerDigits = "digits"
CheckerDigits is the name of the checker.
const CheckerEmail = "email"
CheckerEmail is the name of the checker.
const CheckerFqdn = "fqdn"
CheckerFqdn is the name of the checker.
const CheckerIP = "ip"
CheckerIP is the name of the checker.
const CheckerIPV4 = "ipv4"
CheckerIPV4 is the name of the checker.
const CheckerIPV6 = "ipv6"
CheckerIPV6 is the name of the checker.
const CheckerISBN = "isbn"
CheckerISBN is the name of the checker.
const CheckerLuhn = "luhn"
CheckerLuhn is the name of the checker.
const CheckerMac = "mac"
CheckerMac is the name of the checker.
const CheckerMax = "max"
CheckerMax is the name of the checker.
const CheckerMaxLength = "max-length"
CheckerMaxLength is the name of the checker.
const CheckerMin = "min"
CheckerMin is the name of the checker.
const CheckerMinLength = "min-length"
CheckerMinLength is the name of the checker.
const CheckerRegexp = "regexp"
CheckerRegexp is the name of the checker.
const CheckerRequired = "required"
CheckerRequired is the name of the checker.
const CheckerSame = "same"
CheckerSame is the name of the checker.
const CheckerURL = "url"
CheckerURL is the name of the checker.
const NormalizerLower = "lower"
NormalizerLower is the name of the normalizer.
const NormalizerTitle = "title"
NormalizerTitle is the name of the normalizer.
const NormalizerTrim = "trim"
NormalizerTrim is the name of the normalizer.
const NormalizerTrimLeft = "trim-left"
NormalizerTrimLeft is the name of the normalizer.
const NormalizerTrimRight = "trim-right"
NormalizerTrimRight is the name of the normalizer.
const NormalizerUpper = "upper"
NormalizerUpper is the name of the normalizer.
const ResultNotASCII = "NOT_ASCII"
ResultNotASCII indicates that the given string contains non-ASCII characters.
const ResultNotAlphanumeric = "NOT_ALPHANUMERIC"
ResultNotAlphanumeric indicates that the given string contains non-alphanumeric characters.
const ResultNotCidr = "NOT_CIDR"
ResultNotCidr indicates that the given value is not a valid CIDR.
const ResultNotCreditCard = "NOT_CREDIT_CARD"
ResultNotCreditCard indicates that the given value is not a valid credit card number.
const ResultNotDigits = "NOT_DIGITS"
ResultNotDigits indicates that the given string contains non-digit characters.
const ResultNotEmail = "NOT_EMAIL"
ResultNotEmail indicates that the given string is not a valid email.
const ResultNotFqdn = "NOT_FQDN"
ResultNotFqdn indicates that the given string is not a valid FQDN.
const ResultNotIP = "NOT_IP"
ResultNotIP indicates that the given value is not an IP address.
const ResultNotIPV4 = "NOT_IP_V4"
ResultNotIPV4 indicates that the given value is not an IPv4 address.
const ResultNotIPV6 = "NOT_IP_V6"
ResultNotIPV6 indicates that the given value is not an IPv6 address.
const ResultNotISBN = "NOT_ISBN"
ResultNotISBN indicates that the given value is not a valid ISBN.
const ResultNotLuhn = "NOT_LUHN"
ResultNotLuhn indicates that the given number is not valid based on the Luhn algorithm.
const ResultNotMac = "NOT_MAC"
ResultNotMac indicates that the given value is not an MAC address.
const ResultNotMatch = "NOT_MATCH"
ResultNotMatch indicates that the given string does not match the regexp pattern.
const ResultNotMax = "NOT_MIN"
ResultNotMax indicates that the given value is above the defined maximum.
const ResultNotMaxLength = "NOT_MAX_LENGTH"
ResultNotMaxLength indicates that the length of the given value is above the defined number.
const ResultNotMin = "NOT_MIN"
ResultNotMin indicates that the given value is below the defined minimum.
const ResultNotMinLength = "NOT_MIN_LENGTH"
ResultNotMinLength indicates that the length of the given value is below the defined number.
const ResultNotSame = "NOT_SAME"
ResultNotSame indicates that the given two values are not equal to each other.
const ResultNotURL = "NOT_URL"
ResultNotURL indicates that the given value is not a valid URL.
Variables ¶
This section is empty.
Functions ¶
func FailIfNoPanic ¶
FailIfNoPanic fails if test didn't panic. Use this function with the defer.
Types ¶
type CheckFunc ¶
CheckFunc defines the checker function.
func MakeRegexpChecker ¶
MakeRegexpChecker makes a regexp checker for the given regexp expression with the given invalid result.
type MakeFunc ¶
MakeFunc defines the maker function.
func MakeRegexpMaker ¶
MakeRegexpMaker makes a regexp checker maker for the given regexp expression with the given invalid result.
type Result ¶
type Result string
Result is a unique textual identifier for the mistake.
const ResultRequired Result = "REQUIRED"
ResultRequired indicates that the required value is missing.
const ResultValid Result = "VALID"
ResultValid result indicates that the user input is valid.
func IsAlphanumeric ¶
IsAlphanumeric checks if the given string consists of only alphanumeric characters.
func IsAmexCreditCard ¶
IsAmexCreditCard checks if the given valie is a valid AMEX credit card.
func IsAnyCreditCard ¶
IsAnyCreditCard checks if the given value is a valid credit card number.
func IsCidr ¶
IsCidr checker checks if the value is a valid CIDR notation IP address and prefix length.
func IsDinersCreditCard ¶
IsDinersCreditCard checks if the given valie is a valid Diners credit card.
func IsDiscoveryCreditCard ¶
IsDiscoveryCreditCard checks if the given valie is a valid Discovery credit card.
func IsJcbCreditCard ¶
IsJcbCreditCard checks if the given valie is a valid JCB 15 credit card.
func IsMac ¶
IsMac checks if the given value is a valid an IEEE 802 MAC-48, EUI-48, EUI-64, or a 20-octet IP over InfiniBand link-layer address.
func IsMasterCardCreditCard ¶
IsMasterCardCreditCard checks if the given valie is a valid MasterCard credit card.
func IsMaxLength ¶
IsMaxLength checks if the length of the given value is less than the given maximum length.
func IsMinLength ¶
IsMinLength checks if the length of the given value is greather than the given minimum length.
func IsRequired ¶
func IsRequired(v interface{}) Result
IsRequired checks if the given required value is present.
func IsUnionPayCreditCard ¶
IsUnionPayCreditCard checks if the given valie is a valid UnionPay credit card.
func IsVisaCreditCard ¶
IsVisaCreditCard checks if the given valie is a valid Visa credit card.