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
Access gin request Context from custom validators #2741
Comments
Related to this: #1489 I agree that this could be helpful. The validator library supports contextual validation if you call For example, in my case, I'd like to make a field required or not, based on a query param. If gin context was passed on to the validator, I could do that. I imagine the ValidateStructCtx(context.Context, interface{}) error Or if this cannot be done, because it's a breaking change, then an "extension" interface could be defined, similar to what @samber proposed: type StructValidatorWithContext interface {
StructValidator
ValidateStructCtx(context.Context, interface{}) error
} And then, when binding, the code could check if the validator implementation is an instance of |
I have also encountered this issue, which can help enhance the form validation function. I look forward to going online soon. |
The
StructValidator
interface does not allow passing*gin.Context
.For example, I would like to access
c.Params
from my validator.Current interface signature:
It would be very nice to add an interface such as:
The text was updated successfully, but these errors were encountered: