validator

package module
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnexpectedValidationError = errors.New("unexpected validation error").
	WithCode("ERR_UNEXPECTED_VALIDATION_ERROR").
	WithKind(errors.KindInternal)

Functions

This section is empty.

Types

type Option

type Option func(*Validator)

func WithJSONFieldNames added in v1.9.0

func WithJSONFieldNames() Option

func WithTags added in v1.9.0

func WithTags(tags Tags) Option

type StructLevel added in v1.9.0

type StructLevel = validator.StructLevel

type StructLevelFunc added in v1.9.0

type StructLevelFunc = validator.StructLevelFunc

type Tag added in v1.9.0

type Tag interface {
	Alias() string
	Validate() func(fl validator.FieldLevel) bool
	Translate() string
}

type TagCanonicalID added in v1.11.0

type TagCanonicalID struct {
	UnimplementedTag
}

TagCanonicalID validates that a field holds a util.CanonicalID with the prefix given as the tag param, e.g. `validate:"canonical_id=note"`. The field may be a string or any type whose String method renders the id, such as util.CanonicalID itself or a struct embedding it. Its message is registered in paramBracketedTemplates, because the tag param must be the {1} placeholder.

func (TagCanonicalID) Validate added in v1.11.0

func (t TagCanonicalID) Validate() func(fl validator.FieldLevel) bool

type TagEmail added in v1.9.0

type TagEmail struct {
	UnimplementedTag
}

func (TagEmail) Translate added in v1.9.0

func (t TagEmail) Translate() string

type TagPhone added in v1.9.0

type TagPhone struct {
	UnimplementedTag
}

func (TagPhone) Alias added in v1.9.0

func (t TagPhone) Alias() string

func (TagPhone) Translate added in v1.9.0

func (t TagPhone) Translate() string

type TagRequired added in v1.9.0

type TagRequired struct {
	UnimplementedTag
}

func (TagRequired) Translate added in v1.9.0

func (t TagRequired) Translate() string

type Tags added in v1.9.0

type Tags map[string]Tag

type UnimplementedTag added in v1.9.0

type UnimplementedTag struct{}

func (UnimplementedTag) Alias added in v1.9.0

func (t UnimplementedTag) Alias() string

func (UnimplementedTag) Translate added in v1.9.0

func (t UnimplementedTag) Translate() string

func (UnimplementedTag) Validate added in v1.9.0

func (t UnimplementedTag) Validate() func(fl validator.FieldLevel) bool

type Validator

type Validator struct {
	*validator.Validate
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) (*Validator, error)

func (*Validator) Struct added in v1.9.0

func (v *Validator) Struct(s any) error

Struct validates a structs exposed fields, and automatically validates nested structs, unless otherwise specified.

It returns InvalidValidationError for bad values passed in and nil or ValidationErrors as error otherwise. You will need to assert the error if it's not nil eg. err.(validator.ValidationErrors) to access the array of errors.

Jump to

Keyboard shortcuts

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