errors.go 347 B

1234567891011121314151617181920
  1. package mapper
  2. import (
  3. "errors"
  4. validation "github.com/go-ozzo/ozzo-validation/v4"
  5. )
  6. func ToErrorsMap(err error) map[string]string {
  7. res := make(map[string]string)
  8. var validationErrors validation.Errors
  9. if errors.As(err, &validationErrors) {
  10. for field, msg := range validationErrors {
  11. res[field] = msg.Error()
  12. }
  13. }
  14. return res
  15. }