go-playground / validator

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

Proposal: Support validator chaining #1266

Open mxmauro opened 1 month ago

mxmauro commented 1 month ago

Package version:

v10

Enhancement:

Current implementation does not allow to augment predefined validators.

Let's say someone define a custom type and want to add support for isEq, isNe, etc., If he/she calls RegisterValidation, the existing validator will be overriden completely and existing functionality for them must be written again.

Proposal.

To avoid the library to keep a chain of validators and break compatibility adding a new return value that indicates if the callback handled the validator or the library must call the next one in the chain, I simply propose adding a GetRegisterValidation routine so the developer can manage chaining.

If the idea is accepted, I can create a PR.

Regards, Mauro.