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

feat: custom error mgs with tag (generic function) #1120

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thanhphuchuynh
Copy link

Customizing Error Messages with Tags

In addition to specifying constraints for struct fields, we can also customize error messages using tags. To do this, we add a message tag to our struct field tags.

type PaymentInfo struct {
    CreditCardNumber string `validate:"required" errormgs:"Invalid credit card is required xxx"`
    CVV              string `validate:"required,len=3" errormgs:"CVV code must be three digits long"`
}

@thanhphuchuynh thanhphuchuynh requested a review from a team as a code owner June 28, 2023 03:04
@coveralls
Copy link

coveralls commented Jun 28, 2023

Coverage Status

coverage: 73.967% (-0.005%) from 73.972% when pulling cba5d11 on ThanhPhucHuynh:feat/errortag into bd1113d on go-playground:master.

@thanhphuchuynh thanhphuchuynh changed the title feat: custom error mgs with tag feat: custom error mgs with tag (generic function) Jul 4, 2023
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

Successfully merging this pull request may close these issues.

None yet

2 participants