validator
validator copied to clipboard
Feat: tag to select child field
Fixes Or Enhances
This PR adds a feature to allow selecting struct fields or map values for further validation.
This is useful when trying to apply validation tags to a wrapped value without having to use RegisterCustomTypeFunc with all possible types. When using the new sql.Null for example.
Usage
The usage would be similar to that of the dive tag in the sense that validation tags can be specified for the whole field or the selected field depending on whether they are placed before or after the select tag.
type MyStruct struct {
Field sql.Null[uint] `validate:"omitempty,select=V,gt=10"`
}
Limitations
- Only a single select field can be specified.
- Select fields do not support custom names.
Make sure that you've checked the boxes below before you submit PR:
- [x] Tests exist or have been written that cover this particular change.
@go-playground/validator-maintainers