talira

validator

Struct and field validation for Go, based on tags

open sourceMITfree

validator (go-playground/validator) validates Go structs and individual fields from struct tags. It handles cross-field and cross-struct checks, dives into slices, arrays and maps (keys and values), resolves interfaces and custom types such as SQL driver Valuers, supports alias tags and custom validators, reports the JSON field name in its errors and has translatable error messages. It's the default validator of the Gin web framework. MIT licensed.

Problems it solves

  • validate incoming request structs in my Go API
  • check required fields and formats on a Go struct without writing if statements
  • validate nested slices and maps in Go

Features

  • Validation rules from struct tags
  • Cross-field and cross-struct validation
  • Dives into slices, arrays and maps, keys and values
  • Custom validators and alias tags
  • Custom field types such as SQL driver Valuers
  • JSON field names in errors
  • Translatable error messages
  • Default validator in Gin

Alternatives

The same job

These do what validator does.

  1. govalidator Validators and sanitizers for strings, structs and collections in Go

Compare validator with the top 3