Although gvalid
has built-in dozens of common validation rules, in some business scenarios, we need to define custom validation rules, especially some business-related validation rules that can be reused. Of course, gvalid
is so powerful and considerate that it has already thought this through for you. Custom validation rules can achieve flexible and highly reusable validation features.
📄️ Custom Rule - Registration
How to perform custom rule registration and data validation under the GoFrame framework. Detailed explanation on the definition method of custom rules, parameter descriptions, and how to register global and local rules. Example code demonstrates the implementation of two common scenarios: order ID existence validation and user uniqueness validation, allowing developers to flexibly apply custom validation rule features.
📄️ Custom Rule - Input Object
Use custom rules in the GoFrame framework to perform complete data validation on structs. By adding the metadata g.Meta to a struct, you can register and use custom validation rules such as UserCreateReq to validate user creation requests. Sample code demonstrates how to implement and apply custom validation methods to ensure data uniqueness and validity.