vld

package
v0.0.0-...-c3dc23c Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: Unlicense Imports: 13 Imported by: 0

README

vld

a simple http value binder and a simple struct value validator.

Documentation

Index

Constants

View Source
const (
	ErrorTypeMissRequired
	ErrorTypeNumOutOfRange
	ErrorTypeLengthOutOfRange
	ErrorTypeNotMatchRegexp
	ErrorTypeBadTimeValue
	ErrorTypeCanNotCastToNum
	ErrorTypeCanNotCastToBool
	ErrorTypeBadValueType
	ErrorTypeTimeOutOfRange
)
View Source
const (
	RuleTypeInt = RuleType(iota)
	RuleTypeDouble
	RuleTypeBool
	RuleTypeString
	RuleTypeFile
	RuleTypeTime
	RuleTypeBinder
)

Variables

This section is empty.

Functions

func RegisterRegexp

func RegisterRegexp(name string, txt string)

Types

type Binder

type Binder interface {
	FromRequest(*http.Request) *Error
	Validate() *Error
}

type Error

type Error struct {
	Type ErrorType
	Rule *Rule
	// contains filtered or unexported fields
}

func NewError

func NewError(msg string) *Error

func (*Error) Error

func (err *Error) Error() string

type ErrorType

type ErrorType int

func (ErrorType) String

func (er ErrorType) String() string

type Rule

type Rule struct {
	Name     string
	RuleType RuleType
	Gotype   reflect.Type
	IsSlice  bool
	Index    []int

	Optional bool

	MaxInt    *int64
	MinInt    *int64
	MaxDouble *float64
	MinDouble *float64

	MaxLen *int
	MinLen *int

	MaxRuneCount *int
	MinRuneCount *int
	NoTrim       bool
	NoEscape     bool
	Regexp       *regexp.Regexp

	TimeLayout string
	TimeUnit   string
	TimeBegin  *time.Time
	TimeEnd    *time.Time
}

type RuleType

type RuleType int

type Rules

type Rules struct {
	Gotype reflect.Type
	Data   []*Rule
}

func GetRules

func GetRules(t reflect.Type) *Rules

func (*Rules) BindAndValidate

func (rules *Rules) BindAndValidate(req *http.Request, dist reflect.Value) error

func (*Rules) Validate

func (rules *Rules) Validate(v any) error

Jump to

Keyboard shortcuts

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