
validator
A Go library that checks whether structs and fields hold valid data, using tags on struct fields.
- Stars
- 20.2k
- Forks
- 1.5k
- Licence
- MIT
- Language
- Go
- Last update
- 7 days ago
- Type
- Library
What it is
validator is a Go package that checks data against rules you write as tags on struct fields, such as required, email, or minimum and maximum values. It can also compare fields with each other and validate items inside slices, arrays, and maps. It is the default validator used by the gin web framework, according to the README.
- Validate a registration struct so that email, password length, and required fields are checked in one call
- Check that an end date is later than a start date using cross-field tags such as gtfield
- Validate every element of a slice or every key and value of a map with dive
- Return translated error messages for users by using the translations example in the repo
Great for
- Go developers validating request bodies or form data in web APIs
- Teams that want validation rules declared next to struct definitions
- Projects needing cross-field checks, such as a confirm-password field matching a password field
- Developers who need translated or customized error messages
Not ideal for
- Non-programmers, since it is a code library rather than an app (it requires writing Go code)
- Projects not written in Go, because it is a Go package
- Users who need validation rules loaded from a database or UI without code changes; the README describes tag-based rules in code
How to get it
- 1
Install with a package manager
You'll need: Go (version not stated in the provided README)
Install the package
go get github.com/go-playground/validator/v10 - 2
Run it
- Install the package with go get as shown above
- Import github.com/go-playground/validator/v10 in your Go code
- Add validation tags to your struct fields
- Create a validator with validator.New(validator.WithRequiredStructEnabled()) as the README recommends
- Call validate.Struct on your value and check the returned error
- 3
Get the most out of it
- Use WithRequiredStructEnabled when creating the validator, as the README recommends for new users
- Use the struct-level, custom field types, and translations examples in the _examples folder
- Use alias tags to group several validations under one tag name
- Use the field name extraction feature to report JSON names in errors
Downloads
Strengths
- Rules are declared as readable tags next to the struct fields
- Many built-in checks are listed in the README across strings, network addresses, and formats
- Returns errors in a consistent form that can be inspected with errors.As
Trade-offs
- The README says the default behaviour of WithRequiredStructEnabled will change in v11, so new users are advised to opt in now
- Documentation is pointed to pkg.go.dev and the README is partly truncated, so some details must be checked there
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| validator (this) | 20.2k | Library | intermediate | 7 days ago | Go developers validating request bodies or form data in web APIs |
| pydantic | 29.3k | Library | beginner | 4 days ago | Python developers who already use type hints and want runtime checks on incoming data |
| validator.js | 23.7k | Library | beginner | 2 months ago | JavaScript developers validating form or API input on Node.js |
| effect | 17.5k | Library | advanced | 4 days ago | Teams building large or long-lived TypeScript back-end services |
| class-validator | 11.9k | Library | beginner | 8 months ago | TypeScript developers validating request bodies or form data in Node.js or the browser |
| react-hook-form | 44.9k | Library | intermediate | 5 days ago | React developers building forms with several fields |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.