validation

package
v0.0.0-...-766a4ab Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidField = errors.New("invalid field")
View Source
var ErrInvalidStruct = errors.New("invalid struct")

Functions

func RegisterValidation

func RegisterValidation(tag string, f validator.Func) error

RegisterValidation will register a new validation tag, using the given function, on the global validator.

Types

type FieldError

type FieldError struct {
	Namespace       string `json:"namespace"` // can differ when a custom TagNameFunc is registered or
	Field           string `json:"field"`     // by passing alt name to ReportError like below
	StructNamespace string `json:"structNamespace"`
	StructField     string `json:"structField"`
	Tag             string `json:"tag"`
	ActualTag       string `json:"actualTag"`
	Kind            string `json:"kind"`
	Type            string `json:"type"`
	Value           string `json:"value"`
	Param           string `json:"param"`
	Message         string `json:"message"`
}

FieldError is a particular validation error on a particular field.

func (*FieldError) Error

func (e *FieldError) Error() string

Error satisfies the Error interface.

type StructError

type StructError struct {
	Fields []FieldError
}

StructError contains validation errors on individual fields in a struct.

func ValidateStruct

func ValidateStruct(s any) *StructError

ValidateStruct performs validation on the given struct. If validation fails, a non-nil error is returned that contains the details of individual field validation issues.

func (*StructError) Error

func (e *StructError) Error() string

Error satisfies the Error interface.

Jump to

Keyboard shortcuts

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