validator

package module
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 10 Imported by: 0

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 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 (p 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