validate

package module
v0.0.0-...-b132e92 Latest Latest
Warning

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

Go to latest
Published: May 12, 2020 License: MIT Imports: 9 Imported by: 0

README

validate

Go语言验证类

内置规则
规则 备注 示例
number 判断字段是否为数字 number
chsAlohaNum 判断字段是否由汉字、字母和数字组成 chsAlohaNum
alphaNum 判断字段是否由字母和数字组成 alphaNum
length 判断字段长度是否符合要求 length:1,2
colorHex 判断字段是否为16进制的颜色值 colorHex
chsDash 验证某个字段的值只能是汉字、字母、数字和下划线_及破折号- chsDash
chsAlpha 验证某个字段的值只能是汉字、字母 chsAlpha
chs 验证某个字段的值只能是汉字 chs
between 验证某个字段的值是否在某个区间(数值类型) between:1,10
notBetween 验证某个字段的值不在某个范围(数值类型) notBetween:1,10
in 验证某个字段的值是否在指定的值内 in:1,2,3,4
notIn 验证某个字段的值是否不在指定的值内 notIn:1,2,3,4
max 最大值限制 max:10
min 最小值限制 min:10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Float64

func Float64(i interface{}) float64

func Int

func Int(i interface{}) int

func Int64

func Int64(i interface{}) int64

func LeDecodeToFloat64

func LeDecodeToFloat64(b []byte) float64

func LeDecodeToInt64

func LeDecodeToInt64(b []byte) int64

func LeDecodeToUint64

func LeDecodeToUint64(b []byte) uint64

func LeFillUpSize

func LeFillUpSize(b []byte, l int) []byte

func String

func String(i interface{}) string

func Uint64

func Uint64(i interface{}) uint64

Types

type Rule

type Rule struct {
	RuleMethod map[string]interface{}
}

func (*Rule) AddRule

func (r *Rule) AddRule(name string, fun func(value interface{}, rule string, data map[string]interface{}, arg ...string) bool) *Rule

添加自定义规则

func (*Rule) Between

func (r *Rule) Between(value interface{}, rule string, data map[string]interface{}, arg ...string) bool

验证某个字段的值是否在某个区间(数值类型)

func (*Rule) In

func (r *Rule) In(value interface{}, rule string, data map[string]interface{}, arg ...string) bool

验证某个字段的值是否在指定的值内

func (Rule) InArrayString

func (Rule) InArrayString(content string, values []string) bool

判断是否在数组中

func (Rule) IsAlphaNum

func (Rule) IsAlphaNum(value interface{}, rule string, data map[string]interface{}, arg ...string) bool

判断字段是否由字母和数字组成

func (Rule) IsChs

func (Rule) IsChs(value interface{}, rule string, data map[string]interface{}, arg ...string) bool

验证某个字段的值只能是汉字

func (Rule) IsChsAlpha

func (Rule) IsChsAlpha(value interface{}, rule string, data map[string]interface{}, arg ...string) bool

验证某个字段的值只能是汉字、字母

func (Rule) IsChsAlphaNum

func (Rule) IsChsAlphaNum(value interface{}, rule string, data map[string]interface{}, arg ...string) bool

判断字段是否由汉字、字母和数字组成

func (Rule) IsChsDash

func (Rule) IsChsDash(value interface{}, rule string, data map[string]interface{}, arg ...string) bool

验证某个字段的值只能是汉字、字母、数字和下划线_及破折号-

func (Rule) IsColorHex

func (Rule) IsColorHex(value interface{}, rule string, data map[string]interface{}, arg ...string) bool

判断字段是否为16进制的颜色值

func (Rule) IsNumber

func (Rule) IsNumber(value interface{}, rule string, data map[string]interface{}, arg ...string) bool

判断字段是否为数字

func (Rule) Length

func (Rule) Length(value interface{}, rule string, data map[string]interface{}, arg ...string) bool

判断字段长度是否符合要求

func (*Rule) Max

func (r *Rule) Max(value interface{}, rule string, data map[string]interface{}, arg ...string) bool

*

  • 最大值限制
  • 当类型为数值时,判断数值大小
  • 当类型为切片/字符串/通道时,判断成员数或者文本长度
  • 其他类型不进行判断

func (*Rule) Min

func (r *Rule) Min(value interface{}, rule string, data map[string]interface{}, arg ...string) bool

*

  • 最小值限制
  • 当类型为数值时,判断数值大小
  • 当类型为切片/字符串/通道时,判断成员数或者文本长度
  • 其他类型不进行判断

func (*Rule) NotBetween

func (r *Rule) NotBetween(value interface{}, rule string, data map[string]interface{}, arg ...string) bool

验证某个字段的值不在某个范围(数值类型)

func (*Rule) NotIn

func (r *Rule) NotIn(value interface{}, rule string, data map[string]interface{}, arg ...string) bool

验证某个字段的值是否不在指定的值内

type Validate

type Validate struct {
	Rule //规则模块
	// contains filtered or unexported fields
}

func (*Validate) Check

func (v *Validate) Check(values map[string]interface{}, fail bool) bool

规则验证

func (*Validate) GetError

func (v *Validate) GetError() string

读取错误信息

func (*Validate) Init

func (v *Validate) Init() *Validate

初始化验证类

func (*Validate) Scene

func (v *Validate) Scene(sceneName string) *Validate

设置验证场景

func (*Validate) SetMsg

func (v *Validate) SetMsg(msg Validates) *Validate

设置消息规则

func (*Validate) SetRule

func (v *Validate) SetRule(rule Validates) *Validate

设置规则

func (*Validate) SetScene

func (v *Validate) SetScene(scene Validates) *Validate

设置验证场景数据

type Validates

type Validates map[string]string // 验证器所用的数据类型

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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