validators

package
v0.0.0-...-95995d7 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: MIT Imports: 15 Imported by: 1

Documentation

Overview

Package validators GENERATED BY gengo:runtimedoc DON'T EDIT THIS FILE

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRegexpStrfmtValidatorProvider

func NewRegexpStrfmtValidatorProvider(regexpStr string, name string, aliases ...string) internal.ValidatorProvider

func NewStrfmtValidatorProvider

func NewStrfmtValidatorProvider(validate func(unquoteStr string) error, name string, aliases ...string) internal.ValidatorProvider

func RegisterRegexpStrfmtValidator

func RegisterRegexpStrfmtValidator(regexpStr string, name string, aliases ...string)

Types

type FloatValidator

type FloatValidator struct {
	BitSize       int
	MaxDigits     *uint
	DecimalDigits *uint

	Number[float64]
}

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

func (*FloatValidator) Validate

func (validator *FloatValidator) Validate(value jsontext.Value) error

type IntegerValidator

type IntegerValidator[T ~int64 | ~uint64] struct {
	Unsigned bool
	BitSize  uint

	Number[T]
}

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

func (*IntegerValidator[T]) Validate

func (validator *IntegerValidator[T]) Validate(value jsontext.Value) error

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

func (*MapValidator) Validate

func (validator *MapValidator) Validate(value jsontext.Value) error

type Number

type Number[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64] struct {
	Minimum          *T
	Maximum          *T
	MultipleOf       T
	ExclusiveMaximum bool
	ExclusiveMinimum bool
	Enums            []T
}

func (Number[T]) RuntimeDoc

func (v Number[T]) RuntimeDoc(names ...string) ([]string, bool)

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

func (*SliceValidator) Validate

func (validator *SliceValidator) Validate(value jsontext.Value) error

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

func (*StrfmtValidator) Validate

func (validator *StrfmtValidator) Validate(value jsontext.Value) error

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

func (*StringValidator) Validate

func (validator *StringValidator) Validate(value jsontext.Value) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL