validate

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package validate validates structs using rules declared in `validate` struct tags. It is framework-agnostic and stdlib-only, so the web and CLI layers can share one rule model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Field

func Field(value any, tag string) error

Field validates a single value against a rule set, as used for scalar checks. It returns nil when the value passes and a *ValidationError otherwise.

func Struct

func Struct(v any) error

Struct validates v (a struct or pointer to a struct) against its `validate` tags. It returns nil when every rule passes, a *ValidationError collecting the first failure per field, or a wrapped error for malformed tags.

Types

type FieldError

type FieldError struct {
	Field string
	Value any
	Rule  string
}

FieldError describes a single validation failure.

func (FieldError) Error

func (e FieldError) Error() string

type ValidationError

type ValidationError struct {
	Fields []FieldError
}

ValidationError aggregates one or more field failures.

func (*ValidationError) Error

func (e *ValidationError) Error() string

func (*ValidationError) Is

func (e *ValidationError) Is(target error) bool

Jump to

Keyboard shortcuts

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