Skip to content

Commit

Permalink
update readme and add more alias
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Dec 18, 2019
1 parent 90a39ce commit f0b7084
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,10 @@ validator/aliases | description
`in/enum` | Check if the value is in the given enumeration
`notIn` | Check if the value is not in the given enumeration
`contains` | Check if the input value contains the given value
`notContains` | Check if the input value not contains the given value
`not_contains/notContains` | Check if the input value not contains the given value
`string_contains/stringContains` | Check if the input string value is contains the given sub-string
`starts_with/startsWith` | Check if the input string value is starts with the given sub-string
`ends_with/endsWith` | Check if the input string value is ends with the given sub-string
`range/between` | Check that the value is a number and is within the given range
`max/lte` | Check value is less than or equal to the given value
`min/gte` | Check value is greater than or equal to the given value(for `intX` `uintX` `floatX`)
Expand Down
11 changes: 7 additions & 4 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ type GlobalOption struct {
验证器/别名 | 描述信息
-------------------|-------------------------------------------
`required` | 字段为必填项,值不能为空
`required_if` | `required_if:anotherfield,value,...` 如果其它字段 _anotherfield_ 为任一值 _value_ ,则此验证字段必须存在且不为空。
`required_if/requiredIf` | `required_if:anotherfield,value,...` 如果其它字段 _anotherfield_ 为任一值 _value_ ,则此验证字段必须存在且不为空。
`required_unless` | `required_unless:anotherfield,value,...` 如果其它字段 _anotherfield_ 不等于任一值 _value_ ,则此验证字段必须存在且不为空。
`required_with` | `required_with:foo,bar,...` 在其他任一指定字段出现时,验证的字段才必须存在且不为空
`required_with/requiredWith` | `required_with:foo,bar,...` 在其他任一指定字段出现时,验证的字段才必须存在且不为空
`required_with_all` | `required_with_all:foo,bar,...` 只有在其他指定字段全部出现时,验证的字段才必须存在且不为空
`required_without` | `required_without:foo,bar,...` 在其他指定任一字段不出现时,验证的字段才必须存在且不为空
`required_without_all` | `required_without_all:foo,bar,...` 只有在其他指定字段全部不出现时,验证的字段才必须存在且不为空
Expand All @@ -344,9 +344,12 @@ type GlobalOption struct {
`float/isFloat` | 检查值是 float(`floatX`) 类型
`slice/isSlice` | 检查值是 slice 类型(`[]intX` `[]uintX` `[]byte` `[]string` 等).
`in/enum` | 检查值是否在给定的枚举列表中
`notIn` | 检查值不是在给定的枚举列表中
`not_in/notIn` | 检查值不是在给定的枚举列表中
`contains` | 检查输入值是否包含给定的值
`notContains` | 检查输入值是否不包含给定值
`not_contains/notContains` | 检查输入值是否不包含给定值
`string_contains/stringContains` | 检查输入string值是否不包含给定sub-string值
`starts_with/startsWith` | 检查输入string值是否以给定sub-string开始
`ends_with/endsWith` | 检查输入string值是否以给定sub-string结束
`range/between` | 检查值是否为数字且在给定范围内
`max/lte` | 检查输入值小于或等于给定值
`min/gte` | 检查输入值大于或等于给定值(for `intX` `uintX` `floatX`)
Expand Down
7 changes: 5 additions & 2 deletions register.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ var validatorValues = map[string]reflect.Value{
// define validator alias name mapping
var validatorAliases = map[string]string{
// alias -> real name
"in": "enum",
"range": "between",
"in": "enum",
"not_in": "notIn",
"range": "between",
// type
"int": "isInt",
"integer": "isInt",
Expand Down Expand Up @@ -309,4 +310,6 @@ var validatorAliases = map[string]string{
"required_with_all": "requiredWithAll",
"required_without": "requiredWithout",
"required_without_all": "requiredWithoutAll",
// other
"not_contains": "notContains",
}

0 comments on commit f0b7084

Please sign in to comment.