You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As you might know, so many people are using this package for validating http requests.
Error handling is kinda tricky in this case. For example we have a field called first_name but in the error message we can't access this and we get FirstName(golang struct field name).
Can we add one more tag to get the name that we want instead of golang struct filed name?
Here is an example:
type User struct{
FirstName string `validate:"fieldname=first_name,required"`
}
And in error handling:
for _, err := range err.(validator.ValidationErrors) {
fmt.Println(err.FieldName())
}
It's not really nice to get first_name in the request and return FirstName in the response error msg.
I know it can be handled manually with a little bit extra work.
But can you please handle it in the package? because I think it's a common problem.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
As you might know, so many people are using this package for validating http requests.
Error handling is kinda tricky in this case. For example we have a field called
first_name
but in the error message we can't access this and we getFirstName
(golang struct field name).Can we add one more tag to get the name that we want instead of golang struct filed name?
Here is an example:
And in error handling:
It's not really nice to get
first_name
in the request and returnFirstName
in the response error msg.I know it can be handled manually with a little bit extra work.
But can you please handle it in the package? because I think it's a common problem.
Beta Was this translation helpful? Give feedback.
All reactions