- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validator Function Example #1510
Conversation
1.New 2.Run 3.Clone 4.I18n
1.Ci 2.Data 3.Assoc 4.Rules 5.Messages
1.RuleFunc 2.RuleFuncMap
Codecov Report
@@ Coverage Diff @@
## master #1510 +/- ##
==========================================
+ Coverage 70.65% 70.66% +0.01%
==========================================
Files 425 425
Lines 41123 41123
==========================================
+ Hits 29054 29060 +6
+ Misses 10218 10215 -3
+ Partials 1851 1848 -3
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
|
||
// Output: | ||
// The Name field is required | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
虽然是Rule
方法的示例代码,但是里面缺没有用到Rule
方法,我的建议是规则Example
和方法Example
分开,方法Example
就只是简单的一个使用示例代码即可。
其他方法也是如此。
# Conflicts: # util/gvalid/gvalid_z_example_test.go
util/gvalid/gvalid_z_example_test.go
Outdated
} | ||
|
||
// Output: | ||
// The Name field is required | ||
} | ||
|
||
func ExampleValidator_RequiredIf() { | ||
func ExampleValidator_Rule_RequiredIf() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果将所有的规则示例代码都绑定到Rule
方法中,IDE
的代码提示会不会很不友好?
util/gvalid/gvalid_z_example_test.go
Outdated
@@ -1367,3 +1110,246 @@ func ExampleValidator_Regex() { | |||
// The Regex1 value `1234` must be in regex of: [1-9][0-9]{4,14} | |||
// The Regex2 value `01234` must be in regex of: [1-9][0-9]{4,14} | |||
} | |||
|
|||
func ExampleCheckMap() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以修改为ExampleValidator_Data_Map1
util/gvalid/gvalid_z_example_test.go
Outdated
// 账号不能为空 | ||
} | ||
|
||
func ExampleCheckMap2() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以修改为ExampleValidator_Data_Map2
util/gvalid/gvalid_z_example_test.go
Outdated
} | ||
|
||
// Empty string attribute. | ||
func ExampleCheckStruct() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以修改为ExampleValidator_Data_Struct1
util/gvalid/gvalid_z_example_test.go
Outdated
} | ||
|
||
// Empty pointer attribute. | ||
func ExampleCheckStruct2() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以修改为ExampleValidator_Data_Struct2
util/gvalid/gvalid_z_example_test.go
Outdated
} | ||
|
||
// Empty integer attribute. | ||
func ExampleCheckStruct3() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以修改为ExampleValidator_Data_Struct3
util/gvalid/gvalid_z_example_test.go
Outdated
// <nil> | ||
} | ||
|
||
func ExampleValidator_CheckValue() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以修改为ExampleValidator_Data_Value
util/gvalid/gvalid_z_example_test.go
Outdated
// 未成年人不允许注册哟 | ||
} | ||
|
||
func ExampleValidator_CheckMap() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以修改为ExampleValidator_Data_Map3
util/gvalid/gvalid_z_example_test.go
Outdated
// } | ||
} | ||
|
||
func ExampleValidator_CheckStruct() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以修改为ExampleValidator_Data_Struct4
No description provided.