validator

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2021 License: Unlicense Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MissingRequired = _FormErrorType(iota)
	BadValue
)

Variables

View Source
var CustomFormError func(fe *FormError) string
View Source
var ErrPeekManyValuesFromURLParamsOrCookie = errors.New("sha.validator: peek many values from URLParams or cookie")
View Source
var MarkdownTableHeader = "\n|name|type|required|string length range|int value range|list size range|default|regexp|function|description|\n"
View Source
var ParseBool func(v []byte) (bool, error)

Functions

func RegisterBytesFilter

func RegisterBytesFilter(name string, fn func(v []byte) ([]byte, bool))

func RegisterBytesFilterWithDescription

func RegisterBytesFilterWithDescription(name string, fn func(v []byte) ([]byte, bool), description string)

func RegisterRegexp

func RegisterRegexp(name string, rp *regexp.Regexp)

Types

type CustomField

type CustomField interface {
	FormValue(data []byte) bool
}

type Defaulter

type Defaulter interface {
	Default(fieldName string) interface{}
}

type FormError

type FormError struct {
	FormName string
	Type     _FormErrorType
}

func Validate

func Validate(former Former, dist interface{}) (err *FormError, isNil bool)

return value is a ptr, not an interface.

func (*FormError) Error

func (e *FormError) Error() string

func (*FormError) StatusCode

func (e *FormError) StatusCode() int

type Former

type Former interface {
	URLParam(name string) ([]byte, bool)

	QueryValue(name string) ([]byte, bool)
	QueryValues(name string) [][]byte

	BodyValue(name string) ([]byte, bool)
	BodyValues(name string) [][]byte

	FormValue(name string) ([]byte, bool)
	FormValues(name string) [][]byte

	HeaderValue(name string) ([]byte, bool)
	HeaderValues(name string) [][]byte
	CookieValue(name string) ([]byte, bool)
}

type Rule

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

func (*Rule) String

func (rule *Rule) String() string

markdown table row

type Rules

type Rules []*Rule

func GetRules

func GetRules(t reflect.Type) Rules

func (Rules) Document

func (rules Rules) Document() string

func (Rules) String

func (rules Rules) String() string

Jump to

Keyboard shortcuts

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