-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a global validate function (#152)
Having used this library for a while, I think it's finally time to add this function. It's what 99.99% of users want to do, and having to pass around a `protovalidate.Validator` really messes with a ton of functions downstream. There's no actual state that we care about being shared, other than a cache, and I think this is an exception to our no-global rule. If there's major downsides, let's hear them, but I think this is an extremely user-favorable move.
- Loading branch information
Showing
5 changed files
with
65 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,11 +24,6 @@ import ( | |
) | ||
|
||
func Example() { | ||
validator, err := New() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
person := &pb.Person{ | ||
Id: 1234, | ||
Email: "[email protected]", | ||
|
@@ -39,11 +34,11 @@ func Example() { | |
}, | ||
} | ||
|
||
err = validator.Validate(person) | ||
err := Validate(person) | ||
fmt.Println("valid:", err) | ||
|
||
person.Email = "not an email" | ||
err = validator.Validate(person) | ||
err = Validate(person) | ||
fmt.Println("invalid:", err) | ||
|
||
// output: | ||
|
This file contains 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