improve codes

This commit is contained in:
John 2019-06-20 00:04:06 +08:00
parent e48415d932
commit d15268eb22
2 changed files with 8 additions and 6 deletions

View File

@ -7,8 +7,9 @@
package gvalid
import (
"github.com/gogf/gf/g/util/gconv"
"strings"
"github.com/gogf/gf/g/util/gconv"
)
// 检测键值对参数Map
@ -75,7 +76,7 @@ func CheckMap(params interface{}, rules interface{}, msgs ...CustomMsg) *Error {
}
}
// 开始执行校验: 以校验规则作为基础进行遍历校验
value := (interface{})(nil)
var value interface{}
// 这里的rule变量为多条校验规则不包含名字或者错误信息定义
for key, rule := range checkRules {
// 如果规则为空,那么不执行校验
@ -92,7 +93,7 @@ func CheckMap(params interface{}, rules interface{}, msgs ...CustomMsg) *Error {
if value == nil || gconv.String(value) == "" {
required := false
// rule => error
for k, _ := range item {
for k := range item {
if _, ok := mustCheckRulesEvenValueEmpty[k]; ok {
required = true
break

View File

@ -7,10 +7,11 @@
package gvalid
import (
"strings"
"github.com/gogf/gf/g/text/gstr"
"github.com/gogf/gf/g/util/gconv"
"github.com/gogf/gf/third/github.com/fatih/structs"
"strings"
)
// 校验struct对象属性object参数也可以是一个指向对象的指针返回值同CheckMap方法。
@ -121,7 +122,7 @@ func CheckStruct(object interface{}, rules interface{}, msgs ...CustomMsg) *Erro
/* 以下逻辑和CheckMap相同 */
// 开始执行校验: 以校验规则作为基础进行遍历校验
value := (interface{})(nil)
var value interface{}
// 这里的rule变量为多条校验规则不包含名字或者错误信息定义
for key, rule := range checkRules {
value = nil
@ -134,7 +135,7 @@ func CheckStruct(object interface{}, rules interface{}, msgs ...CustomMsg) *Erro
if value == nil || gconv.String(value) == "" {
required := false
// rule => error
for k, _ := range item {
for k := range item {
if _, ok := mustCheckRulesEvenValueEmpty[k]; ok {
required = true
break