Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

any plans to let users pass their own error message? #34

Open
cyberhck opened this issue Feb 22, 2023 · 0 comments
Open

any plans to let users pass their own error message? #34

cyberhck opened this issue Feb 22, 2023 · 0 comments

Comments

@cyberhck
Copy link

cyberhck commented Feb 22, 2023

Currently the error message that you're returning is basically tabbed, new lined and with some special characters.

It'd be nice for us to use our own messages, it'd help with translation and customization.

The API I feel like would help is something like this:

validator := vjson.NewSchema(
    vjson.String("name").Required("{field} is required").MinLength(2, "{field} should be at least {value} characters").MaxLength(3, "{field} should be less than {value} characters"),
    vjson.String("email").Required("{field} is required").Email("{field} must be a valid email"),
    vjson.Integer("subscriptionMonths").Required("{field} is required").Min(0, "{field} can't be negative"),
    vjson.String("plan").Required().Choices([]string{"GOLD", "SILVER"}, "{field} can only be either `GOLD` or `SILVER`"),
)

When I retrieve an error, we could just get a []ValidationError, I can either use the message provided by you, or I could use my own logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant