validation

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: MIT Imports: 6 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Required             = M(utils.VAL_REQUIRED, "required")
	InvalidStringType    = M(utils.VAL_STRING_TYPE, "must be a string")
	InvalidStringLength  = M(utils.VAL_STRING_LEN, "must be between %d and %d characters")
	InvalidStringPattern = M(utils.VAL_STRING_PATTERN, "is not valid")
	InvalidIntType       = M(utils.VAL_INT_TYPE, "must be a number")
	InvalidIntMin        = M(utils.VAL_INT_MIN, "must be greater or equal to %d")
	InvalidIntMax        = M(utils.VAL_INT_MAX, "must be less than or equal to %d")
	InvalidIntRange      = M(utils.VAL_INT_RANGE, "must be between %d and %d")
	InvalidBoolType      = M(utils.VAL_BOOL_TYPE, "must be true or false")
)

Functions

func Configure

func Configure(config Config) error

func Input

func Input() *input

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 BoolFunc

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

func (BoolFunc) Validate

func (v BoolFunc) Validate(value bool, rest typed.Typed, res *Result) bool

type BoolValidator

type BoolValidator interface {
	Validate(value bool, rest typed.Typed, res *Result) bool
}

type Config

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

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 InputBool

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

func Bool

func Bool(field string) *InputBool

func (*InputBool) Coerce

func (i *InputBool) Coerce() *InputBool

func (*InputBool) Default

func (i *InputBool) Default(value bool) *InputBool

func (*InputBool) Func

func (i *InputBool) Func(fn func(field string, value bool, input typed.Typed, res *Result) bool) *InputBool

func (*InputBool) Required

func (i *InputBool) Required() *InputBool

type InputInt

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

func Int

func Int(field string) *InputInt

func (*InputInt) Default

func (i *InputInt) Default(value int) *InputInt

func (*InputInt) Func

func (i *InputInt) Func(fn func(field string, value int, input typed.Typed, res *Result) int) *InputInt

func (*InputInt) Max

func (i *InputInt) Max(max int) *InputInt

func (*InputInt) Min

func (i *InputInt) Min(min int) *InputInt

func (*InputInt) Range

func (i *InputInt) Range(min int, max int) *InputInt

func (*InputInt) Required

func (i *InputInt) Required() *InputInt

type InputString

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

func String

func String(field string) *InputString

func (*InputString) Clone

func (i *InputString) Clone(field string) *InputString

func (*InputString) Convert

func (i *InputString) Convert(fn StringConverter) *InputString

func (*InputString) Default

func (i *InputString) Default(value string) *InputString

func (*InputString) Func

func (*InputString) Length

func (i *InputString) Length(min int, max int) *InputString

func (*InputString) Pattern

func (i *InputString) Pattern(pattern string) *InputString

func (*InputString) Required

func (i *InputString) Required() *InputString

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(value int, rest typed.Typed, res *Result) int

type IntMax

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

func (IntMax) Validate

func (v IntMax) Validate(value int, rest typed.Typed, res *Result) int

type IntMin

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

func (IntMin) Validate

func (v IntMin) Validate(value int, rest typed.Typed, res *Result) int

type IntRange

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

func (IntRange) Validate

func (v IntRange) Validate(value int, rest typed.Typed, res *Result) int

type IntValidator

type IntValidator interface {
	Validate(value int, rest typed.Typed, res *Result) int
}

type Invalid

type Invalid struct {
	Code  uint32 `json:"code"`
	Error string `json:"error"`
	Data  any    `json:"data,omitempty"`
}

type InvalidField

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

type Meta

type Meta struct {
	Code  uint32
	Error string
}

func M

func M(code uint32, error string) Meta

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) Errors

func (r Result) Errors() []any

func (*Result) Invalid

func (r *Result) Invalid(meta Meta, data any)

func (*Result) InvalidField

func (r *Result) InvalidField(field string, meta Meta, data 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 StringConverter

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

type StringFunc

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

func (StringFunc) Clone

func (v StringFunc) Clone(field string) StringValidator

func (StringFunc) Validate

func (v StringFunc) Validate(value string, rest typed.Typed, res *Result) string

type StringFuncValidator

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

type StringLen

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

func (StringLen) Clone

func (v StringLen) Clone(field string) StringValidator

func (StringLen) Validate

func (v StringLen) Validate(value string, rest typed.Typed, res *Result) string

type StringPattern

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

func (StringPattern) Clone

func (v StringPattern) Clone(field string) StringValidator

func (StringPattern) Validate

func (v StringPattern) Validate(value string, rest typed.Typed, res *Result) string

type StringValidator

type StringValidator interface {
	Clone(field string) StringValidator
	Validate(value string, rest typed.Typed, res *Result) string
}

Jump to

Keyboard shortcuts

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