go-playground / validator

:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
MIT License
16.07k stars 1.29k forks source link

feat: Add a tag validation method #1230

Open xgourmandin opened 4 months ago

xgourmandin commented 4 months ago

Enhances

Use case description :

In an application where we let a user configure custom fields and validation, we want to make sure that the tag associated with the field is valid before using it (because the validation library panics if the tag is invalid, which is fine when the library is used with struct annotations, but not very nice when using methods Var, VarCtx, VarWithValue and VarWithValueCtx directly)

in order to validate a user validation tag input, I propose a new method that handles tag validation and returns an error if there is an invalid tag, allowing a library user to handle this error nicely.

The benefits of adding this here instead of in our codebase is that the tag list is always up to date and it handles custom validators too.

Make sure that you've checked the boxes below before you submit PR:

@go-playground/validator-maintainers

coveralls commented 4 months ago

Coverage Status

coverage: 74.184% (+0.01%) from 74.172% when pulling cbdba6fdf0495c130d5d7744a91ef934654c2dab on xgourmandin:master into b328f72e15814aba56e018c06675b8d679ad6e90 on go-playground:master.