-
Notifications
You must be signed in to change notification settings - Fork 580
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 support for custom validations #741
Comments
I'm not sure there is a place for this feature within protoc-gen-validate. Sure, we would achieve being able to execute anon funcs to a method on the base-type but I dont struggle to see why this is necessary. Given your example above, why not just name the anonymous function? main() {
me := &pb.Person {
Name: "viktor",
Age: 23,
}
if err := CustomValidation(me);err!=nil{
panic(err)
}
if err := me.Validate();err!=nil{
panic(err)
}
}
func CustomValidation(person *pb.Person)error{
if person.Age > 100 {
return errAge
}
return nil
} I am nevertheless too conscious of my own idiocy that i simply may not grasp the true power of your feature request, if you think this is the case - please dont hesitate to call me out. |
It would be nice to be able to add some custom validation code that is then "compiled in" to the standard |
We added custom validation expressions to protovalidate, go check it out! we likely won't add this sort of functionality as we want to make the constraints portable across any consumers of the protos. |
Is there a way to add
custom validation
functions to generatedprotobuf
messages ingo
?for example, we can have another function to receive a validation function which receives a message struct and will be validated after calling
validate
orvalidateAll
functionsThe text was updated successfully, but these errors were encountered: