Documentation ¶
Index ¶
- Constants
- type Category
- type Tag
- type Validator
- func Bool(tag string) Validator
- func Byte(tag string) Validator
- func Int(tag string) Validator
- func Int16(tag string) Validator
- func Int32(tag string) Validator
- func Int64(tag string) Validator
- func Int8(tag string) Validator
- func NewCustom(f interface{}, description string) Validator
- func String(tag string) Validator
- func Struct(instance interface{}) Validator
- func Uint(tag string) Validator
- func Uint16(tag string) Validator
- func Uint32(tag string) Validator
- func Uint64(tag string) Validator
- func Uint8(tag string) Validator
Constants ¶
View Source
const OperatorKind = "validator"
OperatorKind means opeartor kind. All operators generated in this package are has kind `validator`.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Category ¶
type Category string
Category distinguishs validation type based on different Validator implementation.
const ( // CategoryVar indicates that the validator can validate basic built-in types. // Types: string, int*, uint*, bool. CategoryVar Category = "Var" // CategoryStruct indicates that the validator can validate struct. CategoryStruct Category = "Struct" // CategoryCustom indicates the validator is a custom validator. CategoryCustom Category = "Custom" )
type Tag ¶
type Tag string
Tag is the validation tag can be used.
const ( TagIsColor Tag = "iscolor" TagHasValue Tag = "required" TagIsDefault Tag = "isdefault" TagHasLengthOf Tag = "len" TagHasMinOf Tag = "min" TagHasMaxOf Tag = "max" TagIsEq Tag = "eq" TagIsNe Tag = "ne" TagIsLt Tag = "lt" TagIsLte Tag = "lte" TagIsGt Tag = "gt" TagIsGte Tag = "gte" TagIsEqField Tag = "eqfield" TagIsEqCrossStructField Tag = "eqcsfield" TagIsNeCrossStructField Tag = "necsfield" TagIsGtCrossStructField Tag = "gtcsfield" TagIsGteCrossStructField Tag = "gtecsfield" TagIsLtCrossStructField Tag = "ltcsfield" TagIsLteCrossStructField Tag = "ltecsfield" TagIsNeField Tag = "nefield" TagIsGteField Tag = "gtefield" TagIsGtField Tag = "gtfield" TagIsLteField Tag = "ltefield" TagIsLtField Tag = "ltfield" TagIsAlpha Tag = "alpha" TagIsAlphanum Tag = "alphanum" TagIsAlphaUnicode Tag = "alphaunicode" TagIsAlphanumUnicode Tag = "alphanumunicode" TagIsNumeric Tag = "numeric" TagIsNumber Tag = "number" TagIsHexadecimal Tag = "hexadecimal" TagIsHEXColor Tag = "hexcolor" TagIsRGB Tag = "rgb" TagIsRGBA Tag = "rgba" TagIsHSL Tag = "hsl" TagIsHSLA Tag = "hsla" TagIsEmail Tag = "email" TagIsURL Tag = "url" TagIsURI Tag = "uri" TagIsBase64 Tag = "base64" TagContains Tag = "contains" TagContainsAny Tag = "containsany" TagContainsRune Tag = "containsrune" TagExcludes Tag = "excludes" TagExcludesAll Tag = "excludesall" TagExcludesRune Tag = "excludesrune" TagIsISBN Tag = "isbn" TagIsISBN10 Tag = "isbn10" TagIsISBN13 Tag = "isbn13" TagIsUUID Tag = "uuid" TagIsUUID3 Tag = "uuid3" TagIsUUID4 Tag = "uuid4" TagIsUUID5 Tag = "uuid5" TagIsASCII Tag = "ascii" TagIsPrintableASCII Tag = "printascii" TagHasMultiByteCharacter Tag = "multibyte" TagIsDataURI Tag = "datauri" TagIsLatitude Tag = "latitude" TagIsLongitude Tag = "longitude" TagIsSSN Tag = "ssn" TagIsIPv4 Tag = "ipv4" TagIsIPv6 Tag = "ipv6" TagIsIP Tag = "ip" TagIsCIDRv4 Tag = "cidrv4" TagIsCIDRv6 Tag = "cidrv6" TagIsCIDR Tag = "cidr" TagIsTCP4AddrResolvable Tag = "tcp4_addr" TagIsTCP6AddrResolvable Tag = "tcp6_addr" TagIsTCPAddrResolvable Tag = "tcp_addr" TagIsUDP4AddrResolvable Tag = "udp4_addr" TagIsUDP6AddrResolvable Tag = "udp6_addr" TagIsUDPAddrResolvable Tag = "udp_addr" TagIsIP4AddrResolvable Tag = "ip4_addr" TagIsIP6AddrResolvable Tag = "ip6_addr" TagIsIPAddrResolvable Tag = "ip_addr" TagIsUnixAddrResolvable Tag = "unix_addr" TagIsMAC Tag = "mac" TagIsHostname Tag = "hostname" TagIsFQDN Tag = "fqdn" TagIsUnique Tag = "unique" )
Tags for ref and doc gen.
const ( TagUTF8HexComma Tag = "0x2C" TagUTF8Pipe Tag = "0x7C" TagAndSeparator Tag = "," TagOrSeparator Tag = "|" TagKeySeparator Tag = "=" TagStructOnly Tag = "structonly" TagNoStructLevel Tag = "nostructlevel" TagOmitempty Tag = "omitempty" TagSkipValidationTag Tag = "-" TagDiveTag Tag = "dive" TagKeysTag Tag = "keys" TagEndKeysTag Tag = "endkeys" TagRequiredTag Tag = "required" TagNamespaceSeparator Tag = "." TagLeftBracket Tag = "[" TagRightBracket Tag = "]" )
Special tags.
type Validator ¶
type Validator interface { definition.Operator // Category indicates validator type. Category() Category // Tag returns tag. Tag() string // Description returns description of current validator. Description() string }
Validator describes an interface for all validator.
func NewCustom ¶
NewCustom calls f for validation, using description for doc gen. User should only do custom validation in f. Validations which can be done by other way should be done in another Operator. Exp: []definition.Operator{NewCustom(f,"custom validation description")} f should be func(ctx context.Context, object AnyType) error
Click to show internal directories.
Click to hide internal directories.