valid

package
v1.2.1-beta3 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RuleRequired = "required"
	RuleLen      = "len"
	RuleMax      = "max"
	RuleMin      = "min"
	RuleRegex    = "regex"
	RulePhone    = "phone"
	RuleEmail    = "email"
)

Variables

This section is empty.

Functions

func AddRuler

func AddRuler(key string, ruler Ruler)

AddRuler add ruler

Types

type Rule

type Rule struct {
	// key
	Key string
	// 翻译后的字段名
	// default Key
	Trans string
	// valid
	Valid string
}

func (*Rule) Check

func (n *Rule) Check(data any) (err error)

Check rule common rule Check

type RuleChain

type RuleChain map[string]Ruler

RuleChain rule chain 设计模式--职责链模式,数组/map

type Ruler

type Ruler func(rule string, data any) error

Ruler ruler

type ValidError

type ValidError map[string]error

valid type

func Valid

func Valid(data any) ValidError

Valid valid

func ValidModel

func ValidModel(data any, model any) ValidError

ValidModel form/single json data

type ValidRule

type ValidRule map[string]*vRule

valid type

func (*ValidRule) String

func (v *ValidRule) String() string

func (*ValidRule) Unmarshal

func (v *ValidRule) Unmarshal(str string)

type Validator

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

func (*Validator) Check

func (v *Validator) Check() (errs ValidError)

Check rule

Jump to

Keyboard shortcuts

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