govalidator
govalidator copied to clipboard
Problem with several validation errors
if ok, err := govalidator.ValidateStruct(user); err != nil {
st := reflect.TypeOf(err)
fmt.Println(st)
// result: govalidator.Errors type
fmt.Println(st.MethodByName("Errors"))
// result: {Errors func(govalidator.Errors) []error <func(govalidator.Errors) []error Value> 1} true
err.Errors()
// result: err.Errors undefined (type error has no field or method Errors)
}
I can't use Errors() method, because ValidateStruct() function returns error type (in function declaration), not Errors:
https://github.com/asaskevich/govalidator/blob/master/validator.go#L534
func ValidateStruct(s interface{}) (bool, error) {
How I can range validation errors ? Now I can use only Error() function, but this function returns all validation errors as string with ";" separator: https://github.com/asaskevich/govalidator/blob/master/error.go#L11
Could you provide a little snippet with full example of issue please?
i think it is clear enough. if you validate a couple of fields - you need to receive a couple of errors, not a one cocatenated string
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.