Comparison of Golang Input Validator Libraries

This is a comparison of some open source golang validation libraries on github. These libraries do not handle data sanitization. Each libraries will have it's strengths and weakness. Let's get started.

go-playground/validator

go-playground/validator implements value validations for structs and individual fields based on tags. It's probably the oldest and most popular validation library out there. It supports complex validation methods such as cross-field comparison, i18n, diving into fields. This library would be great if you have complex validation requirements.

asaskevich/govalidator

asaskevich/govalidator is a package of validators and sanitizers for strings, structs and collections, and is based on validator.js. Similar to go-playground/validator, govalidator uses struct tags to define rules. It also provides individual validation functions and is a little easier to learn. This is a great alternative if you like mature and popular libraries.

go-ozzo/ozzo-validation

go-ozzo/ozzo-validation provides configurable and extensible data validation capabilities. Unlike the previous two libraries, ozzo-validation uses programming constructs instead of struct tags to define rules. This makes it less error-prone and more readable than the other two.

AgentCosmic/xvalid

AgentCosmic/xvalid is a lightweight validation library that can export rules as JSON so browsers can apply the same rules. xvalid is similar to ozzo-validation in that it uses programming constructs instead of struct tags to define rules. Being able to export rules to the browser will help you keep validation rules consistent. This is a great library if you only need simple validation.

Keywords: golang, library, validator, validation, open source, comparison, alternative
Avatar

Contact