Skip to content
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

Merged
merged 18 commits into from
Dec 7, 2021
Merged

Validator Function Example #1510

merged 18 commits into from
Dec 7, 2021

Conversation

huangqian1985
Copy link
Member

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Dec 4, 2021

Codecov Report

Merging #1510 (5af426d) into master (dacc19a) will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            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     
Flag Coverage Δ
go-1.14 70.63% <ø> (+<0.01%) ⬆️
go-1.15 70.64% <ø> (+<0.01%) ⬆️
go-1.16 70.60% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
util/gvalid/gvalid_custom_rule.go 20.00% <0.00%> (-40.00%) ⬇️
util/gvalid/gvalid_validator_check_value.go 93.25% <0.00%> (+0.84%) ⬆️
os/gmutex/gmutex.go 97.36% <0.00%> (+2.63%) ⬆️
net/gtcp/gtcp_pool.go 38.63% <0.00%> (+4.54%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dacc19a...5af426d. Read the comment docs.


// Output:
// The Name field is required
}
Copy link
Member

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就只是简单的一个使用示例代码即可。
其他方法也是如此。

}

// Output:
// The Name field is required
}

func ExampleValidator_RequiredIf() {
func ExampleValidator_Rule_RequiredIf() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果将所有的规则示例代码都绑定到Rule方法中,IDE的代码提示会不会很不友好?

@@ -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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以修改为ExampleValidator_Data_Map1

// 账号不能为空
}

func ExampleCheckMap2() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以修改为ExampleValidator_Data_Map2

}

// Empty string attribute.
func ExampleCheckStruct() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以修改为ExampleValidator_Data_Struct1

}

// Empty pointer attribute.
func ExampleCheckStruct2() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以修改为ExampleValidator_Data_Struct2

}

// Empty integer attribute.
func ExampleCheckStruct3() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以修改为ExampleValidator_Data_Struct3

// <nil>
}

func ExampleValidator_CheckValue() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以修改为ExampleValidator_Data_Value

// 未成年人不允许注册哟
}

func ExampleValidator_CheckMap() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以修改为ExampleValidator_Data_Map3

// }
}

func ExampleValidator_CheckStruct() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以修改为ExampleValidator_Data_Struct4

@gqcn gqcn merged commit 02f0132 into gogf:master Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants