Documentation ¶
Overview ¶
Package validators GENERATED BY gengo:runtimedoc DON'T EDIT THIS FILE
Index ¶
- func NewRegexpStrfmtValidatorProvider(regexpStr string, name string, aliases ...string) internal.ValidatorProvider
- func NewStrfmtValidatorProvider(validate func(unquoteStr string) error, name string, aliases ...string) internal.ValidatorProvider
- func RegisterRegexpStrfmtValidator(regexpStr string, name string, aliases ...string)
- type FloatValidator
- type IntegerValidator
- type MapValidator
- func (validator *MapValidator) Elem() internal.ValidatorOption
- func (validator *MapValidator) Key() internal.ValidatorOption
- func (validator *MapValidator) PostValidate(rv reflect.Value) error
- func (v MapValidator) RuntimeDoc(names ...string) ([]string, bool)
- func (validator *MapValidator) String() string
- func (validator *MapValidator) Validate(value jsontext.Value) error
- type Number
- type SliceValidator
- func (validator *SliceValidator) Elem() internal.ValidatorOption
- func (validator *SliceValidator) PostValidate(rv reflect.Value) error
- func (v SliceValidator) RuntimeDoc(names ...string) ([]string, bool)
- func (validator *SliceValidator) String() string
- func (validator *SliceValidator) Validate(value jsontext.Value) error
- type StrLenMode
- type StrfmtValidator
- type StringValidator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewRegexpStrfmtValidatorProvider ¶
func NewRegexpStrfmtValidatorProvider(regexpStr string, name string, aliases ...string) internal.ValidatorProvider
Types ¶
type FloatValidator ¶
Validator for float32 and float64
Rules:
ranges
@float[min,max] @float[1,10] // value should large or equal than 1 and less or equal than 10 @float(1,10] // value should large than 1 and less or equal than 10 @float[1,10) // value should large or equal than 1 @float[1,) // value should large or equal than 1 @float[,1) // value should less than 1
enumeration
@float{1.1,1.2,1.3} // value should be one of these
multiple of some float value
@float{%multipleOf} @float{%2.2} // value should be multiple of 2.2
max digits and decimal digits. when defined, all values in rule should be under range of them.
@float<MAX_DIGITS,DECIMAL_DIGITS> @float<5,2> // will checkout these values invalid: 1.111 (decimal digits too many), 12345.6 (digits too many)
composes
@float<MAX_DIGITS,DECIMAL_DIGITS>[min,max]
aliases:
@float32 = @float<7> @float64 = @float<15>
func (FloatValidator) RuntimeDoc ¶
func (v FloatValidator) RuntimeDoc(names ...string) ([]string, bool)
func (*FloatValidator) String ¶
func (validator *FloatValidator) String() string
type IntegerValidator ¶
Rules:
ranges
@int[min,max] @int[1,10] // value should large or equal than 1 and less or equal than 10 @int(1,10] // value should large than 1 and less or equal than 10 @int[1,10) // value should large or equal than 1 @int[1,) // value should large or equal than 1 and less than the maxinum of int32 @int[,1) // value should less than 1 and large or equal than the mininum of int32 @int // value should less or equal than maxinum of int32 and large or equal than the mininum of int32
enumeration
@int{1,2,3} // should one of these values
multiple of some integer value
@int{%multipleOf} @int{%2} // should be multiple of 2
bit size in parameter
@int<8> @int<16> @int<32> @int<64>
composes
@int<8>[1,]
aliases:
@int8 = @int<8> @int16 = @int<16> @int32 = @int<32> @int64 = @int<64>
Tips: for JavaScript https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER
int<53>
func (IntegerValidator[T]) RuntimeDoc ¶
func (v IntegerValidator[T]) RuntimeDoc(names ...string) ([]string, bool)
func (*IntegerValidator[T]) SetDefaults ¶
func (validator *IntegerValidator[T]) SetDefaults()
func (*IntegerValidator[T]) String ¶
func (validator *IntegerValidator[T]) String() string
type MapValidator ¶
type MapValidator struct { MinProperties uint64 MaxProperties *uint64 // contains filtered or unexported fields }
Validator for map
Rules:
@map<KEY_RULE, ELEM_RULE>[minSize,maxSize] @map<KEY_RULE, ELEM_RULE>[length] @map<@string{A,B,C},@int[0]>[,100]
func (*MapValidator) Elem ¶
func (validator *MapValidator) Elem() internal.ValidatorOption
func (*MapValidator) Key ¶
func (validator *MapValidator) Key() internal.ValidatorOption
func (*MapValidator) PostValidate ¶
func (validator *MapValidator) PostValidate(rv reflect.Value) error
func (MapValidator) RuntimeDoc ¶
func (v MapValidator) RuntimeDoc(names ...string) ([]string, bool)
func (*MapValidator) String ¶
func (validator *MapValidator) String() string
type Number ¶
type SliceValidator ¶
type SliceValidator struct { MinItems uint64 MaxItems *uint64 // contains filtered or unexported fields }
Validator for slice
Rules:
@slice<ELEM_RULE>[minLen,maxLen] @slice<ELEM_RULE>[length] @slice<@string{A,B,C}>[,100]
Aliases
@array = @slice // and range must to be use length
func (*SliceValidator) Elem ¶
func (validator *SliceValidator) Elem() internal.ValidatorOption
func (*SliceValidator) PostValidate ¶
func (validator *SliceValidator) PostValidate(rv reflect.Value) error
func (SliceValidator) RuntimeDoc ¶
func (v SliceValidator) RuntimeDoc(names ...string) ([]string, bool)
func (*SliceValidator) String ¶
func (validator *SliceValidator) String() string
type StrLenMode ¶
type StrLenMode string
const ( StrLenModeLength StrLenMode = "length" StrLenModeRuneCount StrLenMode = "rune_count" )
func (StrLenMode) RuntimeDoc ¶
func (StrLenMode) RuntimeDoc(names ...string) ([]string, bool)
type StrfmtValidator ¶
type StrfmtValidator struct {
// contains filtered or unexported fields
}
func (*StrfmtValidator) Format ¶
func (validator *StrfmtValidator) Format() string
func (*StrfmtValidator) String ¶
func (validator *StrfmtValidator) String() string
type StringValidator ¶
type StringValidator struct { Pattern string LenMode StrLenMode MinLength uint64 MaxLength *uint64 Enums []string }
Validator for string
Rules:
@string/regexp/ @string{VALUE_1,VALUE_2,VALUE_3} @string<StrLenMode>[from,to] @string<StrLenMode>[length]
ranges
@string[min,max] @string[length] @string[1,10] // string length should large or equal than 1 and less or equal than 10 @string[1,] // string length should large or equal than 1 and less than the maxinum of int32 @string[,1] // string length should less than 1 and large or equal than 0 @string[10] // string length should be equal 10
enumeration
@string{A,B,C} // should one of these values
regexp
@string/\w+/ // string values should match \w+
since we use / as wrapper for regexp, we need to use \ to escape /
length mode in parameter
@string<length> // use string length directly @string<rune_count> // use rune count as string length
composes
@string<>[1,]
aliases:
@char = @string<rune_count>
func (StringValidator) RuntimeDoc ¶
func (v StringValidator) RuntimeDoc(names ...string) ([]string, bool)
func (*StringValidator) String ¶
func (validator *StringValidator) String() string