Introduction
The goframe
framework provides a powerful, easy-to-use, flexible, and easily extensible data/form validation component implemented by the gvalid
component. The gvalid
component implements a very powerful data validation functionality, with dozens of built-in common validation rules. It supports single data multiple rule validation, multi-data multi-rule batch validation, custom error messages, custom regular expression validation, custom validation rule registration, supports i18n
internationalization processing, supports struct tag
rules and prompt information binding and other features, making it currently the most powerful Go
data validation module.
The design inspiration for data validation comes from the classic PHP Laravel
framework https://laravel.com/docs/8.x/validation. Thank you Laravel
❤️
Usage:
import "github.com/gogf/gf/v2/util/gvalid"
API Documentation:
https://pkg.go.dev/github.com/gogf/gf/v2/util/gvalid
Features
The gvalid
component has the following notable features:
- Built-in dozens of common data validation rules, supporting most business scenarios
- Supports
Server
layer and command-line component automated validation - Supports basic types and complex object type parameter validation
- Supports sequential validation and flexible validation result handling
- Supports custom validation error messages
- Supports recursive validation of struct attributes
- Supports custom validation rules
- Supports internationalization feature
I18n
Documents
📄️ Data Validation - Rules
Data validation rules and their applications in the GoFrame framework. The GoFrame framework comes with multiple commonly used validation rules, assisting developers in parameter validation and struct validation when processing data. The article provides a detailed explanation of how to use various validation rules in different scenarios, including required parameters, date formats, numeric ranges, enumeration validation, etc., offering developers a flexible validation mechanism.
📄️ Data Validation - Object
Using the data validation component in the GoFrame framework for data validation, including configuration management and chained operations of the validation object. Detailed examples show single data validation, struct, and map data validation methods to help developers quickly master data validation techniques.
📄️ Data Validation - Result
Using the GoFrame framework for data validation, this document describes the implementation and usage of the gvalid.Error interface. It details methods for obtaining validation error messages, including the impact of sequential and non-sequential validation. Additionally, examples show how to retrieve the first error message from validation errors, providing practical guidance for developers.
🗃️ Data Validation - Data Type
3 items
📄️ Data Validation - Optional Rule
Using the GoFrame framework for data validation, especially focusing on the use of optional validation rules. When the validation rules do not include 'required', optional validation rules do not enforce validation on empty strings or nil values. The document provides multiple practical code examples to demonstrate the process and considerations for implementing optional data validation with the GoFrame framework in Go language, suitable for developers to apply in projects.
📄️ Data Validation - Recursive
The recursive validation feature of the data validation component in the GoFrame framework. Through example code, it demonstrates how to perform nested validation on struct, slice, and map types of data to achieve effective validation of complex data structures. Special note is made on handling empty objects in recursive validation, and empty objects with default values are considered passed and validated.
🗃️ Data Validation - Custom
2 items
📄️ Data Validation - Error Msg
When using the data validation component of the GoFrame framework, customize error messages and support the i18n internationalization feature. By combining with the i18n component, you can easily set error messages in different languages. The document explains in detail how to configure i18n files in English and Chinese, and how to set the error message language through middleware, helping developers to handle internationalization more efficiently.
📄️ Data Validation - Methods
The data validation function in the GoFrame framework, detailing the use of common validation methods including New, Run, Clone, I18n, Bail, and Ci. Through specific examples, it explains how to effectively use these methods for data validation and provides ways to customize validation rules and error messages to help developers better complete data validation tasks for their applications.
📄️ Data Validation - FAQ
The impact of Struct's default values on the required rule and its solutions when using the GoFrame framework for data validation, including using pointer types to bypass default value impacts, combined validation rules, and the Assoc joint validation method to ensure validation accuracy.