Search and commands

↑ ↓ to select · Enter to open · Esc to close

Type to search packages.

main

v1.3.0
github.com/GIN-GONIC/GIN/examples/struct-lvl-validations

Documentation

pkg.go.dev ↗

Table of contents

↓ to select · Enter to jump· Shift+Enter for source

4 matches

Top ↑

Functions

UserStructLevelValidation

func UserStructLevelValidation(v *validator.Validate, structLevel *validator.StructLevel)

UserStructLevelValidation contains custom struct level validations that don't always make sense at the field validation level. For example, this function validates that either FirstName or LastName exist; could have done that with a custom field validation but then would have had to add it to both fields duplicating the logic + overhead, this way it's only validated once.

NOTE: you may ask why wouldn't not just do this outside of validator. Doing this way hooks right into validator and you can combine with validation tags and still have a common error output format.

Types

User

type User struct {
	FirstName string `json:"fname"`
	LastName  string `json:"lname"`
	Email     string `binding:"required,email"`
}

User contains user information.

Dependency graph