improve package gvalid

This commit is contained in:
John Guo
2021-05-19 19:00:34 +08:00
parent 420e0b9ca4
commit fac9ab5c01
4 changed files with 8 additions and 3 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -148,7 +148,7 @@ func (e *validationError) FirstRule() (rule string, err string) {
array := strings.Split(ruleItem, ":")
ruleItem = strings.TrimSpace(array[0])
if err, ok = errorItemMap[ruleItem]; ok {
return ruleStr, err
return ruleItem, err
}
}
}

View File

@ -191,6 +191,11 @@ func Test_Sequence(t *testing.T) {
t.Assert(err.Map()["length"], "账号长度应当在6到16之间")
t.Assert(len(err.Maps()), 2)
t.Assert(len(err.Items()), 2)
t.Assert(err.Items()[0]["passport"]["length"], "账号长度应当在6到16之间")
t.Assert(err.Items()[0]["passport"]["required"], "账号不能为空")
t.Assert(err.Items()[1]["password"]["same"], "两次密码输入不相等")
t.Assert(err.String(), "账号不能为空; 账号长度应当在6到16之间; 两次密码输入不相等")
t.Assert(err.Strings(), []string{"账号不能为空", "账号长度应当在6到16之间", "两次密码输入不相等"})