Version: v0.3.1 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2021 License: Apache-2.0 Imports: 7 Imported by: 16




View Source
const OperatorKind = "validator"

OperatorKind means opeartor kind. All operators generated in this package are has kind `validator`.


This section is empty.


This section is empty.


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 {
	// 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 Bool

func Bool(tag string) Validator

Bool creates validator for bool type.

func Byte

func Byte(tag string) Validator

Byte creates validator for byte type.

func Int

func Int(tag string) Validator

Int creates validator for int type.

func Int16

func Int16(tag string) Validator

Int16 creates validator for int16 type.

func Int32

func Int32(tag string) Validator

Int32 creates validator for int32 type.

func Int64

func Int64(tag string) Validator

Int64 creates validator for int64 type.

func Int8

func Int8(tag string) Validator

Int8 creates validator for int8 type.

func NewCustom

func NewCustom(f interface{}, description string) Validator

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

func String

func String(tag string) Validator

String creates validator for string type.

func Struct

func Struct(instance interface{}) Validator

Struct returns an operator to validate a structs exposed fields, and automatically validates nested structs, unless otherwise specified and also allows passing of context.Context for contextual validation information.

func Uint

func Uint(tag string) Validator

Uint creates validator for uint type.

func Uint16

func Uint16(tag string) Validator

Uint16 creates validator for uint16 type.

func Uint32

func Uint32(tag string) Validator

Uint32 creates validator for uint32 type.

func Uint64

func Uint64(tag string) Validator

Uint64 creates validator for uint64 type.

func Uint8

func Uint8(tag string) Validator

Uint8 creates validator for uint8 type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL