validate

package
v1.1.8-0...-5ee8a8c Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

README

Validate

a similar pipeline validator

Syntax


 key[/key translator][/split divide (default is |)]@verify1[:verify1 param]|verify2

Syntax such as

key1@required|int|min:1     
key2/key2_translator@required|string|min:1|max:12      
key3@sometimes|required|date      

Global register keys translator

note:only is key


//global register keys translator //note:only is key
func init() { 
    //register keys translator //note:is key
    //suck as:verify error
    //en:    The name field is required
    //zh-cn: {0} 不能空 

    lang.RegisterKeys("zh-cn", map[string]string{
	    "name":    "姓名",
	    "age":     "年龄",
	    "address": "地址",
    })

    //other langs 
}

Support for the validator

note:will continue to add new validator

  • date
  • email
  • int
  • ip
  • match
  • max
  • min
  • required
  • sometimes

etc

Documentation

Index

Constants

View Source
const (
	Invalid = reflect.Invalid
	Bool    = reflect.Bool
	Int     = reflect.Int
	Int8    = reflect.Int8
	Int16   = reflect.Int16
	Int32   = reflect.Int32
	Int64   = reflect.Int64
	Uint    = reflect.Uint
	Uint8   = reflect.Uint8
	Uint16  = reflect.Uint16
	Uint32  = reflect.Uint32
	Uint64  = reflect.Uint64
	Float32 = reflect.Float32
	Float64 = reflect.Float64
	String  = reflect.String
	Date    = reflect.UnsafePointer + 255
	Email   = Date + 1
)

A Kind represents the specific kind of type that a Type represents. The zero Kind is not a valid kind.

Variables

This section is empty.

Functions

func Register

func Register(name string, vf VerifyFunc)

Register a validator provide by the vfuncs name

Types

type Val

type Val struct {
	Key, TranKey, Param string
	Real, Expect        reflect.Kind
	Value               interface{}
}

Val a validate value

type Validator

type Validator struct {
	Lang string //default en
}

Validator a validate

func (*Validator) Request

func (c *Validator) Request(data url.Values, rules ...string) error

Request verify that the url.Values data is validate data rules is validate rule such as:

key1@required|int|min:1
key2/key2_translator@required|string|min:1|max:12
key3@sometimes|required|date

func (*Validator) Struct

func (c *Validator) Struct(data interface{}) error

Struct verify that the a struct or each element is a struct int the slice or each element is a struct int the map data is validate data

func (*Validator) Trans

func (c *Validator) Trans(key string, param ...string) string

Trans translator

type Verify

type Verify interface {
	Verify(v *Validator) error
}

Verify is customer verify interface

type VerifyFunc

type VerifyFunc interface {
	Verify(v *Validator, val Val) (bool, bool, error)
}

VerifyFunc is verify interface

Jump to

Keyboard shortcuts

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