structLevel

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

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 Gender

type Gender uint
const (
	Male Gender = iota + 1
	Female
)

func (Gender) String

func (gender Gender) String() string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL