asaskevich / govalidator

[Go] Package of validators and sanitizers for strings, numerics, slices and structs
MIT License
6.02k stars 556 forks source link

Problem with several validation errors #147

Open Alejka opened 8 years ago

Alejka commented 8 years ago
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

asaskevich commented 8 years ago

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

hotrush commented 7 years ago

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

sergeyglazyrindev commented 2 years ago

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.