validation

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, validator Validator)

Register a validator with name

Types

type Context

type Context struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Context validation context

func NewContext

func NewContext(ctx context.Context, options ...Option) *Context

NewContext create a new validation context

func (*Context) Clear

func (c *Context) Clear()

Clear reset context's status

func (*Context) Error

func (c *Context) Error() string

Error return all validation errors

func (*Context) Errors

func (c *Context) Errors() []string

Errors return all validation errors

func (*Context) IsValid

func (c *Context) IsValid() bool

IsValid return validataion result

func (*Context) Validate

func (c *Context) Validate(formName, key string, value interface{}) *Context

Validate validate a parameter

func (*Context) ValidateGroup

func (c *Context) ValidateGroup(formName string) *Group

ValidateGroup return a validation group

type Group

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

Group help to add keys and values to a group quickly

func (*Group) WithNames

func (g *Group) WithNames(keys ...string) *Group

WithNames push parameters

func (*Group) WithValues

func (g *Group) WithValues(values ...interface{}) *Context

WithValues push values

type Option

type Option func(ctx *Context)

Option 变数设定

func WithForms

func WithForms(raw string) Option

WithForms 指定表单设定

type Validator

type Validator interface {
	Validate(form models.Form, params, key string, value interface{}) (string, bool)
}

Validator implement this interface in order to register your custom validator

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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