Data is the most important thing about the application. Receiving, checking, and standardizing data is always necessary. Therefore, the gFly framework has a built-in library to check data from users.
Validation provides a set of predefined rules sufficient to check today’s common data. However, you can also optionally add any new checking rules of your own.
Note
IMPORTANT!
Define validation inside DTO struct file by using tag validate
Examples
// SignIn struct to describe login user.typeSignInstruct {
Usernamestring`json:"username" validate:"required,email,lte=255"`Passwordstring`json:"password" validate:"required,gte=6"`}
// User contains user informationtypeUserstruct {
FirstNamestring`validate:"required"`LastNamestring`validate:"required"`Ageuint8`validate:"gte=0,lte=130"`Emailstring`validate:"required,email"`Genderstring`validate:"oneof=male female prefer_not_to"`FavouriteColorstring`validate:"iscolor"`// alias for 'hexcolor|rgb|rgba|hsl|hsla'Addresses []*Address`validate:"required,dive,required"`// a person can have a home and cottage...}
// Address houses a users address informationtypeAddressstruct {
Streetstring`validate:"required"`Citystring`validate:"required"`Planetstring`validate:"required"`Phonestring`validate:"required"`}
Rules
Default rules about Fields, Network, Strings, Format, Comparisons, Other, Aliases
Fields:
Tag
Description
eqcsfield
Field Equals Another Field (relative)
eqfield
Field Equals Another Field
fieldcontains
Check the indicated characters are present in the Field
fieldexcludes
Check the indicated characters are not present in the field
gtcsfield
Field Greater Than Another Relative Field
gtecsfield
Field Greater Than or Equal To Another Relative Field