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

Add functions that get max slice elements from struct tags #83

Merged
merged 2 commits into from
Mar 26, 2024

Conversation

ivan4th
Copy link
Contributor

@ivan4th ivan4th commented Mar 26, 2024

This adds MustGetMaxElements and related functions that parse struct tags to get max number of elements

@ivan4th ivan4th requested a review from fasmat March 26, 2024 16:34
Copy link

codecov bot commented Mar 26, 2024

Codecov Report

Attention: Patch coverage is 56.00000% with 22 lines in your changes are missing coverage. Please review.

Project coverage is 41.8%. Comparing base (f2cc357) to head (fb06c47).

Files Patch % Lines
tag.go 58.3% 10 Missing and 10 partials ⚠️
generate.go 0.0% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master     #83     +/-   ##
========================================
+ Coverage    39.1%   41.8%   +2.6%     
========================================
  Files           5       6      +1     
  Lines         697     720     +23     
========================================
+ Hits          273     301     +28     
+ Misses        399     384     -15     
- Partials       25      35     +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

tag.go Outdated
// the struct passed as the v argument based on the 'scale' tag. It returns an error if v
// is not a structure, if max is not specified for the field, the field doesn't exist or
// there's a problem parsing the tag.
func GetMaxElementsFromValue(v any, fieldName string) (uint32, error) {
Copy link
Member

@fasmat fasmat Mar 26, 2024

Choose a reason for hiding this comment

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

The Get prefix for a function/method is usually redundant and unusual for go.

Suggested change
func GetMaxElementsFromValue(v any, fieldName string) (uint32, error) {
func MaxScaleElementsForField(v any, fieldName string) (uint32, error) {

tag.go Outdated
return maxElements
}

func getMaxElements(tag reflect.StructTag) (uint32, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func getMaxElements(tag reflect.StructTag) (uint32, error) {
func maxScaleElements(tag reflect.StructTag) (uint32, error) {

tag.go Outdated Show resolved Hide resolved
@ivan4th
Copy link
Contributor Author

ivan4th commented Mar 26, 2024

Removed Get prefixes except in MustGetMaxElements b/c MustMaxElements would be somewhat confusing

@fasmat fasmat merged commit 236def4 into master Mar 26, 2024
10 checks passed
@fasmat fasmat deleted the feature/get-max-elements branch March 26, 2024 17:30
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.

2 participants