validator

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatError

func FormatError(err error) error

FormatError formats validator errors using the universal translator

func RegisterValidation

func RegisterValidation(f func(v *validator.Validate, translator ut.Translator))

RegisterValidation registers a custom validation with translation

func Struct

func Struct(s any) error

Struct validates a struct without context

func StructCtx

func StructCtx(ctx context.Context, s any) error

StructCtx validates a struct with context

func StructExceptCtx

func StructExceptCtx(ctx context.Context, s any, omitField ...string) error

StructExceptCtx validates a struct with context, omitting specified fields

func Translator

func Translator() ut.Translator

Translator returns the universal translator instance

func Validate

func Validate() *validator.Validate

Validate returns the validator instance

Types

type EnumValuer added in v0.1.2

type EnumValuer interface {
	Values() []string
}

EnumValuer is optionally implemented by enums that can list their valid values. When implemented, validation error messages will include the allowed values.

type FieldError

type FieldError struct {
	Field   string `json:"field"`
	Message string `json:"message"`
}

FieldError represents a single field validation error

type ValidEnum added in v0.1.2

type ValidEnum interface {
	IsValid() bool
}

ValidEnum is implemented by enum types that can validate their value.

type ValidationError

type ValidationError struct {
	Message     string       `json:"message"`
	FieldErrors []FieldError `json:"fieldErrors"`
}

ValidationError represents validation errors

func (ValidationError) Error

func (v ValidationError) Error() string

Jump to

Keyboard shortcuts

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