A Go library for validating structs using field tags with built-in and custom rules.
Govalid is a Go library for struct validation using field tags, allowing developers to define constraints directly in their struct definitions. It simplifies data validation by supporting built-in rules, custom rules, and nested validation for complex data structures like slices, arrays, and nested structs.
Go developers building applications that require robust input validation, such as APIs, web services, or data processing pipelines, where validation logic needs to be declarative and maintainable.
Developers choose Govalid for its simplicity and extensibility, offering a clean tag-based syntax, support for custom rules, and the ability to handle nested structures with the 'dive' rule, distinguishing validation errors from internal errors for better error handling.
Struct validation using tags
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Define validation rules directly in struct tags with a concise syntax like `valid:"req|min:3|max:20"`, making code self-documenting and reducing boilerplate.
Register custom rules using `govalid.Rule`, allowing any validation logic, such as the 'fun' rule in the README that checks for exclamation marks in strings.
Use the `dive` rule to validate elements within pointers, slices, arrays, and nested structs, enabling complex data structures without extra code.
Differentiate between validation errors and internal errors via `govalid.ValidationError`, aiding in debugging and proper error responses, as shown in the error handling example.
Only offers basic rules like req, min, max, in, and dive; lacks common validators for emails, URLs, or dates, requiring custom implementations for everyday use.
Cannot validate fields in relation to each other (e.g., start date before end date), limiting it for complex business logic that depends on multiple fields.
Heavy reliance on struct tags can make definitions verbose and harder to maintain, especially with many or complex validation rules.