How can I define custom error message? I don't want to make a detailed explanation. I just want to make a brief statement.
type RegisterRequest struct {
Username string `validate:"required"` // UsernameIsRequired
Email string `validate:"required,email"` // EmailIsRequired,EmailIsNotValid
Password string `validate:"required,gte=8,lte=32"` // PasswordRequired,PasswordGreaterThan8,PasswordLessThan32
}
@bakbuz take a look at the example of the translation for custom error message by locale https://github.com/go-playground/validator/blob/master/_examples/translations/main.go it's geared towards more general messages for each tag.
If you need more custom messages I recommend creating your own messaging layer using all the information returned by each error, see the simple example for details https://github.com/go-playground/validator/blob/master/_examples/simple/main.go#L69
Thank you very much.
Most helpful comment
@bakbuz take a look at the example of the translation for custom error message by locale https://github.com/go-playground/validator/blob/master/_examples/translations/main.go it's geared towards more general messages for each tag.
If you need more custom messages I recommend creating your own messaging layer using all the information returned by each error, see the simple example for details https://github.com/go-playground/validator/blob/master/_examples/simple/main.go#L69