A Go package for struct and field validation with cross-field, cross-struct, and deep diving into slices, arrays, and maps.
Validator is a Go package that provides struct and field validation using tags. It solves the problem of ensuring data integrity in Go applications by offering a declarative way to validate structs, including complex scenarios like cross-field validation and deep diving into nested collections. It is widely used as the default validator for the Gin web framework.
Go developers building web services, APIs, or any application requiring robust input validation, especially those using structs to model data.
Developers choose Validator for its extensive built-in validation tags, high performance, and flexibility in handling complex validation scenarios like nested structures and custom types, all while maintaining a simple tag-based API.
:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Includes over 100 validation tags for strings, networks, formats, and more, covering common use cases like email, UUID, and credit card numbers without custom code.
Benchmarks show minimal allocations and fast execution (e.g., 27.88 ns/op for field success), making it suitable for high-throughput applications.
Supports diving into slices, arrays, and maps at any depth, including map keys and values, enabling complex data structure validation.
Offers customizable i18n-aware error messages, facilitating localization for global applications directly from the README examples.
Validation logic is embedded in struct tags, making it harder to debug, test, or dynamically modify compared to programmatic approaches.
The call for maintainers and upcoming v11 changes (e.g., WithRequiredStructEnabled opt-in) indicate potential breaking changes and slower community support.
Requires type casting errors to ValidationErrors (e.g., err.(validator.ValidationErrors)), adding boilerplate and risk of panics if not handled carefully.