Description
validator is a Go package that validates struct fields and values based on tags. It supports cross-field and cross-struct validations, both with built-in tags and custom validators, and it can dive into slices, arrays and maps to validate any or all levels of a nested value, including map keys and values. It determines the underlying type of an interface before validating, and handles custom types such as SQL driver valuers. Validation tags can be grouped under an alias so one name stands for several checks, and the field name used in errors can be taken from a custom source, such as a JSON name. Errors are customizable and can be translated. The package is the default validator for the Gin web framework, and the README explains the upgrade from version 8 to version 9 for Gin users. Installation uses go get with the version 10 path. Validation functions return an error that is nil or a set of validation errors, and the README explains how to check it. The README includes a call for maintainers, and the detailed usage reference is hosted on pkg.go.dev. The package is for Go developers who check request payloads, configuration and form data in their services.…
Highlights
- Struct and field validation by tags
- Cross-field and cross-struct checks
- Dives into slices, arrays and maps
- Custom tag aliases and error field names
- Translatable error messages
Ratings & Reviews
No ratings yet
Be the first to rate Validator.
People also visit
Validator FAQ
What does validator do?
It validates Go structs and fields based on struct tags, including cross-field checks and checks inside slices, arrays and maps.
How do I install it?
Run go get github.com/go-playground/validator/v10 and import it.
Is it used by Gin?
Yes. It is the default validator for the Gin web framework.
Can I customize error messages?
Yes. Error messages are customizable and i18n aware, according to the README.
Where is the usage reference?
On pkg.go.dev, linked from the README.
What are the best Validator alternatives?
Popular alternatives to Validator include Zog and Go Webapp Sample. See all Validator alternatives



