validation

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2023 License: MIT Imports: 10 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Choice added in v0.0.5

func Choice[T any](valid []T) any

func Configure

func Configure(config Config) error

func Max

func Max(max any) any

func Min

func Min(min any) any

func Range

func Range(min any, max any) any

Types

type AnyFunc added in v0.0.5

type AnyFunc struct {
	// contains filtered or unexported fields
}

func (AnyFunc) Validate added in v0.0.5

func (v AnyFunc) Validate(field Field, value any, object typed.Typed, input typed.Typed, res *Result) any

type AnyRule added in v0.0.5

type AnyRule interface {
	Validate(field Field, value any, object typed.Typed, input typed.Typed, res *Result) any
	// contains filtered or unexported methods
}

type AnyValidator added in v0.0.5

type AnyValidator struct {
	// contains filtered or unexported fields
}

func Any added in v0.0.5

func Any() *AnyValidator

func (*AnyValidator) Default added in v0.0.5

func (v *AnyValidator) Default(value any) *AnyValidator

func (*AnyValidator) Func added in v0.0.5

func (v *AnyValidator) Func(fn func(field Field, value any, object typed.Typed, input typed.Typed, res *Result) any) *AnyValidator

func (*AnyValidator) Required added in v0.0.5

func (v *AnyValidator) Required() *AnyValidator

type ArrayMax added in v0.0.5

type ArrayMax struct {
	// contains filtered or unexported fields
}

func (ArrayMax) Validate added in v0.0.5

func (r ArrayMax) Validate(field Field, values []typed.Typed, object typed.Typed, input typed.Typed, res *Result) []typed.Typed

type ArrayMin added in v0.0.5

type ArrayMin struct {
	// contains filtered or unexported fields
}

func (ArrayMin) Validate added in v0.0.5

func (r ArrayMin) Validate(field Field, values []typed.Typed, object typed.Typed, input typed.Typed, res *Result) []typed.Typed

type ArrayRange added in v0.0.5

type ArrayRange struct {
	// contains filtered or unexported fields
}

func (ArrayRange) Validate added in v0.0.5

func (r ArrayRange) Validate(field Field, values []typed.Typed, object typed.Typed, input typed.Typed, res *Result) []typed.Typed

type ArrayRule added in v0.0.5

type ArrayRule interface {
	Validate(field Field, value []typed.Typed, object typed.Typed, input typed.Typed, res *Result) []typed.Typed
	// contains filtered or unexported methods
}

type ArrayValidator added in v0.0.5

type ArrayValidator struct {
	// contains filtered or unexported fields
}

func Array added in v0.0.5

func Array() *ArrayValidator

func (*ArrayValidator) Default added in v0.0.5

func (v *ArrayValidator) Default(value []typed.Typed) *ArrayValidator

func (*ArrayValidator) Max added in v0.0.5

func (v *ArrayValidator) Max(max int) *ArrayValidator

func (*ArrayValidator) Min added in v0.0.5

func (v *ArrayValidator) Min(min int) *ArrayValidator

func (*ArrayValidator) Range added in v0.0.5

func (v *ArrayValidator) Range(min int, max int) *ArrayValidator

func (*ArrayValidator) Required added in v0.0.5

func (v *ArrayValidator) Required() *ArrayValidator

func (*ArrayValidator) Validator added in v0.0.5

func (v *ArrayValidator) Validator(validator *ObjectValidator) *ArrayValidator

type BoolFunc

type BoolFunc struct {
	// contains filtered or unexported fields
}

func (BoolFunc) Validate

func (v BoolFunc) Validate(field Field, value bool, object typed.Typed, input typed.Typed, res *Result) bool

type BoolRule added in v0.0.5

type BoolRule interface {
	Validate(field Field, value bool, object typed.Typed, input typed.Typed, res *Result) bool
	// contains filtered or unexported methods
}

type BoolValidator

type BoolValidator struct {
	// contains filtered or unexported fields
}

func Bool

func Bool() *BoolValidator

func (*BoolValidator) Default added in v0.0.5

func (v *BoolValidator) Default(value bool) *BoolValidator

func (*BoolValidator) Func added in v0.0.5

func (v *BoolValidator) Func(fn func(field Field, value bool, object typed.Typed, input typed.Typed, res *Result) bool) *BoolValidator

func (*BoolValidator) Required added in v0.0.5

func (v *BoolValidator) Required() *BoolValidator

type Config

type Config struct {
	PoolSize  uint16 `json:"pool_size"`
	MaxErrors uint16 `json:"max_errors"`
}

type DataChoice added in v0.0.5

type DataChoice[T any] struct {
	Valid []T `json:"valid"`
}

type DataMax

type DataMax struct {
	Max any `json:"max"`
}

type DataMin

type DataMin struct {
	Min any `json:"min"`
}

type DataRange

type DataRange struct {
	Min any `json:"min"`
	Max any `json:"max"`
}

type Field added in v0.0.5

type Field struct {
	// The name of the actual field that we need to look up. This is
	// always equal to the last element in Path
	Name string

	// strings.Join(Path, ".")
	Flat string

	// The full path of the field.
	// Could be a single value, like: ["name"],
	// Could be nested, like ["user", "name"],
	// Could contain placeholders for array indexex, like: ["users", "", name]
	Path []string
}

func NewField added in v0.0.5

func NewField(name string) Field

func NewIndexedField added in v0.0.5

func NewIndexedField(name string) Field

type FloatFunc added in v0.0.5

type FloatFunc struct {
	// contains filtered or unexported fields
}

func (FloatFunc) Validate added in v0.0.5

func (v FloatFunc) Validate(field Field, value float64, object typed.Typed, input typed.Typed, res *Result) float64

type FloatMax added in v0.0.5

type FloatMax struct {
	// contains filtered or unexported fields
}

func (FloatMax) Validate added in v0.0.5

func (r FloatMax) Validate(field Field, value float64, object typed.Typed, input typed.Typed, res *Result) float64

type FloatMin added in v0.0.5

type FloatMin struct {
	// contains filtered or unexported fields
}

func (FloatMin) Validate added in v0.0.5

func (r FloatMin) Validate(field Field, value float64, object typed.Typed, input typed.Typed, res *Result) float64

type FloatRange added in v0.0.5

type FloatRange struct {
	// contains filtered or unexported fields
}

func (FloatRange) Validate added in v0.0.5

func (r FloatRange) Validate(field Field, value float64, object typed.Typed, input typed.Typed, res *Result) float64

type FloatRule added in v0.0.5

type FloatRule interface {
	Validate(field Field, value float64, object typed.Typed, input typed.Typed, res *Result) float64
	// contains filtered or unexported methods
}

type FloatValidator added in v0.0.5

type FloatValidator struct {
	// contains filtered or unexported fields
}

func Float added in v0.0.5

func Float() *FloatValidator

func (*FloatValidator) Default added in v0.0.5

func (v *FloatValidator) Default(value float64) *FloatValidator

func (*FloatValidator) Func added in v0.0.5

func (v *FloatValidator) Func(fn func(field Field, value float64, object typed.Typed, input typed.Typed, res *Result) float64) *FloatValidator

func (*FloatValidator) Max added in v0.0.5

func (v *FloatValidator) Max(max float64) *FloatValidator

func (*FloatValidator) Min added in v0.0.5

func (v *FloatValidator) Min(min float64) *FloatValidator

func (*FloatValidator) Range added in v0.0.5

func (v *FloatValidator) Range(min float64, max float64) *FloatValidator

func (*FloatValidator) Required added in v0.0.5

func (v *FloatValidator) Required() *FloatValidator

type InputValidator

type InputValidator interface {
	// contains filtered or unexported methods
}

type IntFunc

type IntFunc struct {
	// contains filtered or unexported fields
}

func (IntFunc) Validate

func (v IntFunc) Validate(field Field, value int, object typed.Typed, input typed.Typed, res *Result) int

type IntMax

type IntMax struct {
	// contains filtered or unexported fields
}

func (IntMax) Validate

func (r IntMax) Validate(field Field, value int, object typed.Typed, input typed.Typed, res *Result) int

type IntMin

type IntMin struct {
	// contains filtered or unexported fields
}

func (IntMin) Validate

func (r IntMin) Validate(field Field, value int, object typed.Typed, input typed.Typed, res *Result) int

type IntRange

type IntRange struct {
	// contains filtered or unexported fields
}

func (IntRange) Validate

func (r IntRange) Validate(field Field, value int, object typed.Typed, input typed.Typed, res *Result) int

type IntRule added in v0.0.5

type IntRule interface {
	Validate(field Field, value int, object typed.Typed, input typed.Typed, res *Result) int
	// contains filtered or unexported methods
}

type IntValidator

type IntValidator struct {
	// contains filtered or unexported fields
}

func Int

func Int() *IntValidator

func (*IntValidator) Default added in v0.0.5

func (v *IntValidator) Default(value int) *IntValidator

func (*IntValidator) Func added in v0.0.5

func (v *IntValidator) Func(fn func(field Field, value int, object typed.Typed, input typed.Typed, res *Result) int) *IntValidator

func (*IntValidator) Max added in v0.0.5

func (v *IntValidator) Max(max int) *IntValidator

func (*IntValidator) Min added in v0.0.5

func (v *IntValidator) Min(min int) *IntValidator

func (*IntValidator) Range added in v0.0.5

func (v *IntValidator) Range(min int, max int) *IntValidator

func (*IntValidator) Required added in v0.0.5

func (v *IntValidator) Required() *IntValidator

type Invalid

type Invalid struct {
	Code  uint32 `json:"code"`
	Error string `json:"error"`
	Data  any    `json:"data"` //TODO: add omitempty https://github.com/goccy/go-json/issues/391
}

func InvalidArrayMaxLength added in v0.0.5

func InvalidArrayMaxLength(max int) Invalid

func InvalidArrayMinLength added in v0.0.5

func InvalidArrayMinLength(min int) Invalid

func InvalidArrayRangeLength added in v0.0.5

func InvalidArrayRangeLength(min int, max int) Invalid

func InvalidArrayStringType added in v0.0.5

func InvalidArrayStringType() Invalid

Not used by this library (yet), but is used by callers of this library. We put it here because (a) we expect to use this eventually here and (b) we want this to be consistent across all users of this library

func InvalidArrayType added in v0.0.5

func InvalidArrayType() Invalid

func InvalidBoolType

func InvalidBoolType() Invalid

func InvalidFloatMax added in v0.0.5

func InvalidFloatMax(max float64) Invalid

func InvalidFloatMin added in v0.0.5

func InvalidFloatMin(min float64) Invalid

func InvalidFloatRange added in v0.0.5

func InvalidFloatRange(min float64, max float64) Invalid

func InvalidFloatType added in v0.0.5

func InvalidFloatType() Invalid

func InvalidIntMax

func InvalidIntMax(max int) Invalid

func InvalidIntMin

func InvalidIntMin(min int) Invalid

func InvalidIntRange

func InvalidIntRange(min int, max int) Invalid

func InvalidIntType

func InvalidIntType() Invalid

func InvalidStringChoice added in v0.0.5

func InvalidStringChoice(choices []string) Invalid

func InvalidStringLength

func InvalidStringLength(min int, max int) Invalid

func InvalidStringPattern

func InvalidStringPattern(errorMessage ...string) Invalid

func InvalidStringType

func InvalidStringType() Invalid

func InvalidUUIDType added in v0.0.5

func InvalidUUIDType() Invalid

func Required

func Required() Invalid

type InvalidField

type InvalidField struct {
	Invalid
	Field string `json:"field"`
}

type ObjectValidator added in v0.0.5

type ObjectValidator struct {
	// contains filtered or unexported fields
}

func Object added in v0.0.5

func Object() *ObjectValidator

func (*ObjectValidator) Field added in v0.0.5

func (o *ObjectValidator) Field(fieldName string, validator InputValidator) *ObjectValidator

func (*ObjectValidator) Validate added in v0.0.5

func (o *ObjectValidator) Validate(input typed.Typed, res *Result) bool

object validation called on the root

func (*ObjectValidator) ValidateArgs added in v0.0.5

func (o *ObjectValidator) ValidateArgs(args *fasthttp.Args, res *Result) (typed.Typed, bool)

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool(count uint16, maxErrors uint16) *Pool

func (*Pool) Checkout

func (p *Pool) Checkout() *Result

func (*Pool) Depleted

func (p *Pool) Depleted() uint64

func (*Pool) Len

func (p *Pool) Len() int

type Result

type Result struct {
	// contains filtered or unexported fields
}

func Checkout

func Checkout() *Result

func NewResult

func NewResult(maxErrors uint16) *Result

func (*Result) AddInvalid added in v0.0.5

func (r *Result) AddInvalid(invalid Invalid)

func (*Result) AddInvalidField added in v0.0.5

func (r *Result) AddInvalidField(field Field, invalid Invalid)

func (*Result) ArrayIndex added in v0.0.5

func (r *Result) ArrayIndex(i int)

func (*Result) BeginArray added in v0.0.5

func (r *Result) BeginArray()

func (*Result) EndArray added in v0.0.5

func (r *Result) EndArray()

func (Result) Errors

func (r Result) Errors() []any

func (Result) IsValid

func (r Result) IsValid() bool

func (Result) Len

func (r Result) Len() uint64

func (*Result) Release

func (r *Result) Release()

type StringChoice added in v0.0.5

type StringChoice struct {
	// contains filtered or unexported fields
}

func (StringChoice) Validate added in v0.0.5

func (r StringChoice) Validate(field Field, value string, object typed.Typed, input typed.Typed, res *Result) string

type StringConverter

type StringConverter func(field Field, value string, object typed.Typed, input typed.Typed, res *Result) any

type StringFunc

type StringFunc struct {
	// contains filtered or unexported fields
}

func (StringFunc) Validate

func (r StringFunc) Validate(field Field, value string, object typed.Typed, input typed.Typed, res *Result) string

type StringFuncValidator

type StringFuncValidator func(field Field, value string, object typed.Typed, input typed.Typed, res *Result) string

type StringLen

type StringLen struct {
	// contains filtered or unexported fields
}

func (StringLen) Validate

func (r StringLen) Validate(field Field, value string, object typed.Typed, input typed.Typed, res *Result) string

type StringPattern

type StringPattern struct {
	// contains filtered or unexported fields
}

func (StringPattern) Validate

func (r StringPattern) Validate(field Field, value string, object typed.Typed, input typed.Typed, res *Result) string

type StringRule added in v0.0.5

type StringRule interface {
	Validate(field Field, value string, object typed.Typed, input typed.Typed, res *Result) string
	// contains filtered or unexported methods
}

type StringValidator

type StringValidator struct {
	// contains filtered or unexported fields
}

func String

func String() *StringValidator

func (*StringValidator) Choice added in v0.0.5

func (v *StringValidator) Choice(valid ...string) *StringValidator

func (*StringValidator) Convert added in v0.0.5

func (*StringValidator) Default added in v0.0.5

func (v *StringValidator) Default(value string) *StringValidator

func (*StringValidator) Func added in v0.0.5

func (*StringValidator) Length added in v0.0.5

func (v *StringValidator) Length(min int, max int) *StringValidator

func (*StringValidator) Pattern added in v0.0.5

func (v *StringValidator) Pattern(pattern string, errorMessage ...string) *StringValidator

func (*StringValidator) Required added in v0.0.5

func (v *StringValidator) Required() *StringValidator

type UUIDValidator added in v0.0.5

type UUIDValidator struct {
	// contains filtered or unexported fields
}

func UUID added in v0.0.5

func UUID() *UUIDValidator

func (*UUIDValidator) Default added in v0.0.5

func (v *UUIDValidator) Default(value string) *UUIDValidator

func (*UUIDValidator) Required added in v0.0.5

func (v *UUIDValidator) Required() *UUIDValidator

Jump to

Keyboard shortcuts

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