Add optional Validate() error method#102
Open
peczenyj wants to merge 3 commits intodmarkham:masterfrom
Open
Conversation
1 task
nodivbyzero
added a commit
to go-playground/validator
that referenced
this pull request
Apr 16, 2025
## Fixes Or Enhances This Pull Requests adds a new tag called `isvalid` If the field is marked with the validator tag `isvalid`, the type must implement the interface `Validate() error` and the return must be nil to be considered `valid` A possible use case is: when dealing with Enumerations, the type can support a method `Validate() error` to check if the value is in specific the range defined. If we use [enumer](https://github.com/dmarkham/enumer) it generates a `IsA<Type>() bool` method that can be used to verify if the enumeration is valid or not, instead force the `oneof` tag (that needs to be always updated when we add one new value. I wrote a pull request to add a Validate method on enumerations [here](dmarkham/enumer#102) and the interface `Validate() error` seems pretty common. It may clash with existing tags that people may register, this is something that I don't know how to solve. **Make sure that you've checked the boxes below before you submit PR:** - [X] Tests exist or have been written that cover this particular change. @go-playground/validator-maintainers --------- Co-authored-by: nodivbyzero <nodivbyzero@gmail.com>
Contributor
Author
|
conflict solved |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
port of #82
this pull request will adds an optional method
Validate() error-- and this is a very common interface -- that return an error if theIsA<Type>() boolreturns false.The advantage over
IsA<Type>() boolis the interface. Makes easier to integrate with other tools such as validators