validate

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Email

func Email(field, value string) error

Email validates an email address.

func MaxLen

func MaxLen(field, value string, max int) error

MaxLen ensures a maximum string length.

func MinLen

func MinLen(field, value string, min int) error

MinLen ensures a minimum string length.

func Register

func Register(name string, fn ValidatorFunc)

Register adds a custom validator by name.

func Required

func Required(field, value string) error

Required ensures a non-empty string.

func SetHooks

func SetHooks(next Hooks)

SetHooks replaces validation hooks.

func Struct

func Struct(value any) error

Struct validates struct fields using `validate` tags.

Types

type Errors

type Errors struct {
	Fields []FieldError
}

Errors holds multiple field errors.

func As

func As(err error) (*Errors, bool)

As extracts validation errors if present.

func (*Errors) Error

func (e *Errors) Error() string

Error implements the error interface.

type FieldError

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

FieldError describes a validation failure for a field.

type Hooks

type Hooks struct {
	OnError func(value any, err error)
}

Hooks configures validation callbacks.

type ValidatorFunc

type ValidatorFunc func(field string, value reflect.Value, param string) *FieldError

ValidatorFunc validates a field with an optional parameter.

Jump to

Keyboard shortcuts

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