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: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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