Skip to content

Commit

Permalink
recurse when errors are govalidator.Errors inside govalidator.Errors
Browse files Browse the repository at this point in the history
This fixes qor#4
  • Loading branch information
r00tkillah committed Jun 24, 2019
1 parent f364bca commit 3b80f2d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ func validate(scope *gorm.Scope) {
}
}

func flatValidatorErrors(validatorErrors govalidator.Errors) []govalidator.Error {
resultErrors := []govalidator.Error{}
func flatInner(validatorErrors govalidator.Errors, flattened *[]govalidator.Error) {
for _, validatorError := range validatorErrors.Errors() {
if errors, ok := validatorError.(govalidator.Errors); ok {
for _, e := range errors {
resultErrors = append(resultErrors, e.(govalidator.Error))
}
flatInner(errors, flattened)
}
if e, ok := validatorError.(govalidator.Error); ok {
resultErrors = append(resultErrors, e)
*flattened = append(*flattened, e)
}
}
}

func flatValidatorErrors(validatorErrors govalidator.Errors) []govalidator.Error {
resultErrors := []govalidator.Error{}
flatInner(validatorErrors, &resultErrors)
return resultErrors
}

Expand Down

0 comments on commit 3b80f2d

Please sign in to comment.