validate.go 477 B

12345678910111213141516171819202122
  1. package i18n
  2. import (
  3. "unicode"
  4. ut "github.com/go-playground/universal-translator"
  5. "github.com/go-playground/validator/v10"
  6. )
  7. func FormatValidateErrors(errors error, trans ut.Translator) map[string]string {
  8. formatted := make(map[string]string)
  9. if errors != nil {
  10. for _, err := range errors.(validator.ValidationErrors) {
  11. r := []rune(err.Translate(trans))
  12. r[0] = unicode.ToUpper(r[0])
  13. formatted[err.StructNamespace()] = string(r)
  14. }
  15. }
  16. return formatted
  17. }