validator

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: Unlicense Imports: 17 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|field bytes size|int value range|list size range|default|regexp|function|description|\n"
View Source
var NameCast func(fieldName string) string
View Source
var ParseBool func(v []byte) (bool, error)
View Source
var PasswordValidator func(data []byte) bool = func(data []byte) bool {
	s := utils.S(data)
	var (
		hasMinLen  = false
		hasUpper   = false
		hasLower   = false
		hasNumber  = false
		hasSpecial = false
	)
	if len(s) >= 6 {
		hasMinLen = true
	}
	for _, char := range s {
		switch {
		case unicode.IsUpper(char):
			hasUpper = true
		case unicode.IsLower(char):
			hasLower = true
		case unicode.IsNumber(char):
			hasNumber = true
		case unicode.IsPunct(char) || unicode.IsSymbol(char):
			hasSpecial = true
		default:
			return false
		}
	}
	return hasMinLen && hasUpper && hasLower && hasNumber && hasSpecial
}
View Source
var Undefined = &_undefined{}

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 Defaulter

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

type Document added in v0.0.5

type Document interface {
	Tags() []string
	Description() string
	Input() string
	Output() string
}

type Field added in v0.0.5

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

type FormError

type FormError struct {
	FormName string
	Type     _FormErrorType
}

func BindAndValidateForm added in v0.0.5

func BindAndValidateForm(former Former, dist interface{}) (err *FormError)

return value is a ptr, not an interface.

func ValidateStruct added in v0.0.5

func ValidateStruct(vPtr interface{}) (err *FormError)

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 Password added in v0.0.5

type Password []byte

func (*Password) BcryptHash added in v0.0.5

func (p *Password) BcryptHash(cost int) ([]byte, error)

func (*Password) FormValue added in v0.0.5

func (p *Password) FormValue(data []byte) bool

func (*Password) MatchTo added in v0.0.5

func (p *Password) MatchTo(hash []byte) bool

type Rules

type Rules []*_Rule

func GetRules

func GetRules(t reflect.Type) Rules

func (Rules) Len added in v0.0.5

func (rules Rules) Len() int

func (Rules) Less added in v0.0.5

func (rules Rules) Less(i, j int) bool

func (Rules) String

func (rules Rules) String() string

func (Rules) Swap added in v0.0.5

func (rules Rules) Swap(i, j int)

type SimpleDocument added in v0.0.5

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

func NewDocument added in v0.0.5

func NewDocument(input interface{}, output interface{}) *SimpleDocument

func (*SimpleDocument) AddTags added in v0.0.5

func (m *SimpleDocument) AddTags(tags ...string) *SimpleDocument

func (*SimpleDocument) Description added in v0.0.5

func (m *SimpleDocument) Description() string

func (*SimpleDocument) Input added in v0.0.5

func (m *SimpleDocument) Input() string

func (*SimpleDocument) Output added in v0.0.5

func (m *SimpleDocument) Output() string

func (*SimpleDocument) SetDescription added in v0.0.5

func (m *SimpleDocument) SetDescription(desc string) *SimpleDocument

func (*SimpleDocument) Tags added in v0.0.5

func (m *SimpleDocument) Tags() []string

Jump to

Keyboard shortcuts

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