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

Feat: tag to select child field #1235

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

MysteriousPotato
Copy link
Contributor

Fixes Or Enhances

This PR adds a feature to allow selecting struct fields or map values for further validation.

This is useful when trying to apply validation tags to a wrapped value without having to use RegisterCustomTypeFunc with all possible types. When using the new sql.Null for example.

Usage

The usage would be similar to that of the dive tag in the sense that validation tags can be specified for the whole field or the selected field depending on whether they are placed before or after the select tag.

type MyStruct struct {
   Field sql.Null[uint] `validate:"omitempty,select=V,gt=10"`
}

Limitations

  • Only a single select field can be specified.
  • Select fields do not support custom names.

Make sure that you've checked the boxes below before you submit PR:

  • Tests exist or have been written that cover this particular change.

@go-playground/validator-maintainers

@MysteriousPotato MysteriousPotato requested a review from a team as a code owner February 22, 2024 16:22
@coveralls
Copy link

coveralls commented Feb 22, 2024

Coverage Status

coverage: 74.217% (+0.009%) from 74.208%
when pulling 7eb58af on MysteriousPotato:main
into a0f74b0 on go-playground:master.

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

2 participants