Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UserStructLevelValidation ¶
func UserStructLevelValidation(sl validator.StructLevel)
UserStructLevelValidation contains custom structure level validations that don't always make sense at the field validation level. For example, this function validates whether FirstName or LastName exists. It could do this with a custom field validation, but then would have to add it to both fields, duplicating logic + overhead, and this way it only validated once.
Types ¶
type Address ¶
type Address struct {
Street string `validate:"required"`
City string `validate:"required"`
Planet string `validate:"required"`
Phone string `validate:"required"`
}
Address houses a users address information.
type User ¶
type User struct {
FirstName string `json:"fname"`
LastName string `json:"lname"`
Age uint8 `validate:"gte=0,lte=130"`
Email string `json:"e-mail" validate:"required,email"`
FavouriteColor string `validate:"hexcolor|rgb|rgba"`
Addresses []*Address `validate:"required,dive,required"`
Gender Gender `json:"gender" validate:"required,gender_custom_validation"`
}
User contains user information.
Click to show internal directories.
Click to hide internal directories.