govalidator icon indicating copy to clipboard operation
govalidator copied to clipboard

Problem with several validation errors

Open Alejka opened this issue 8 years ago • 3 comments

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

Alejka avatar Aug 24 '16 20:08 Alejka

Could you provide a little snippet with full example of issue please?

asaskevich avatar Aug 26 '16 07:08 asaskevich

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

hotrush avatar Oct 31 '16 16:10 hotrush

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.

sergeyglazyrindev avatar Oct 17 '21 21:10 sergeyglazyrindev