validation

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Validate

func Validate(ctx context.Context, values map[string]any, validators ...Validator) error

Validate runs validators and returns structured errors.

Types

type Error

type Error struct {
	Code    string
	Message string
}

Error is one structured validation error.

type Errors

type Errors struct {
	Fields map[string][]Error
}

Errors stores validation errors keyed by field name.

func (*Errors) Add

func (e *Errors) Add(field, code, message string)

Add appends one field error.

func (*Errors) Error

func (e *Errors) Error() string

func (*Errors) Has

func (e *Errors) Has(field string) bool

Has reports whether a field has any errors.

type Validator

type Validator func(context.Context, map[string]any, *Errors)

Validator validates a value map and appends structured errors.

func Choice

func Choice(field string, choices ...any) Validator

func Constraint

func Constraint(field string, check func(context.Context, map[string]any) (bool, error)) Validator

func Custom

func Custom(field, code string, check func(context.Context, any) error) Validator

func Email

func Email(field string) Validator

func FieldLevel

func FieldLevel(field string, check func(context.Context, any) error) Validator

func MaxLength

func MaxLength(field string, max int) Validator

func MaxValue

func MaxValue(field string, max float64) Validator

func MinLength

func MinLength(field string, min int) Validator

func MinValue

func MinValue(field string, min float64) Validator

func ModelLevel

func ModelLevel(code string, check func(context.Context, map[string]any) error) Validator

func Regex

func Regex(field string, pattern *regexp.Regexp) Validator

func Required

func Required(field string) Validator

Required validates non-empty values.

func Slug

func Slug(field string) Validator

func Type

func Type(field string, example any) Validator

Type validates the value has the same concrete type as example.

func URL

func URL(field string) Validator

func UUID

func UUID(field string) Validator

func Unique

func Unique(field string, check func(context.Context, any) (bool, error)) Validator

func UniqueForDate

func UniqueForDate(field string, check func(context.Context, time.Time, any) (bool, error)) Validator

func UniqueForMonth

func UniqueForMonth(field string, check func(context.Context, time.Time, any) (bool, error)) Validator

func UniqueForYear

func UniqueForYear(field string, check func(context.Context, time.Time, any) (bool, error)) Validator

Jump to

Keyboard shortcuts

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