Validator: Support json in structs?

Created on 6 Sep 2018  路  2Comments  路  Source: go-playground/validator

Package version eg. v8, v9:

v9

Issue, Question or Enhancement:

Question:
Is there any way to change the error message to show the JSON field and not the struct field name?

Code sample, to showcase or reproduce:

type TestStruct struct {
    Name     string `json:"name" validate:"required"`
    Lastname string `json:"lastname" validate:"required"`
    Address  string `json:"address" validate:"required"`
    Phone    string `json:"phone" validate:"required"`
}

Instead of Key: 'TestStruct.Address' Error:Field validation for 'Address' failed on the 'required' tag
I want to show to user

Error in validation for 'address' failed on the 'required' tag
question

Most helpful comment

Yes @droslean, as in the docs RegisterTagNameFunc

here is an example in the tests.

All 2 comments

Yes @droslean, as in the docs RegisterTagNameFunc

here is an example in the tests.

@joeybloggs Thanks a lot. This is what I was looking for.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

phenrigomes picture phenrigomes  路  5Comments

dumindu picture dumindu  路  5Comments

gwan284 picture gwan284  路  4Comments

alexyans picture alexyans  路  3Comments

deschmih picture deschmih  路  3Comments