gvalid

package
v0.0.0-...-c9a36a8 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

数据校验. 本来打算取名gvalidator的,名字太长了,缩写一下

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(val interface{}, rules string, msgs interface{}, params ...map[string]interface{}) map[string]string

检测单条数据的规则,其中params参数为非必须参数,可以传递所有的校验参数进来,进行多参数对比(部分校验规则需要) msgs为自定义错误信息,由于同一条数据的校验规则可能存在多条,为方便调用,参数类型支持string/map[string]string,允许传递多个自定义的错误信息,如果类型为string,那么中间使用"|"符号分隔多个自定义错误 values参数为表单联合校验参数,对于需要联合校验的规则有效,如:required-*、same、different

func CheckMap

func CheckMap(params map[string]interface{}, rules map[string]string, msgs ...map[string]interface{}) map[string]map[string]string

检测键值对参数Map,注意返回参数是一个2维的关联数组,第一维键名为参数键名,第二维为带有错误的校验规则名称,值为错误信息

func CheckObject

func CheckObject(object interface{}, rules map[string]string, msgs ...map[string]interface{}) map[string]map[string]string

校验struct对象属性,object参数也可以是一个指向对象的指针,返回值同CheckMap方法

func SetDefaultErrorMsgs

func SetDefaultErrorMsgs(msgs map[string]string)

替换默认的错误提示为指定的自定义提示 主要作用: 1、便于多语言错误提示设置; 2、默认错误提示信息不满意;

Types

This section is empty.

Jump to

Keyboard shortcuts

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