govalidator
govalidator copied to clipboard
Dynamic validation
Hi,
Is it possible to set validation on a particular field dynamically. I.e. not by using tags? One problem I have is I want to validate my ID field but only when its being validated in an update method? ID should be missing when it is the create method.
Sorry if this is already answered somewhere.
Cheers,
Hi! Currently its not possible with help of library, but you could to create your own middleware that will accept an object and validate all necessary fields inside itself, something like this:
import v "github.com/asaskevich/govalidator"
...
type User struct {
Name string
Email string
}
...
func ValidateMyStruct(u User) bool {
return v.IsEmail(u.Email)
}
Hello guys! I forked this package cause owner disappeared. Hope, he will be back, but it would be easier to merge these changes back if he is back Link to my repo: create issue there and we'll discuss it.