Documentation
¶
Overview ¶
Package validation provides typed, fluent validation of application values. Rules run only during Validate or ValidateContext. Evaluation collects the first violation per field by default, in declaration order. Validator configures broader collection, global stopping, and message formatting. Unexpected rule errors abort evaluation and remain operational errors rather than client-facing messages.
Builders can be branched and reused without sharing evaluation state. Slices and application dependencies are borrowed; callers must not mutate inputs during evaluation and must coordinate any state used by custom rules.
Index ¶
- func Validate(fields ...Field) error
- func ValidateContext(ctx context.Context, fields ...Field) error
- type BoolField
- func (b BoolField[T]) Accepted() BoolField[T]
- func (b BoolField[T]) Check(check func(context.Context, T) error) BoolField[T]
- func (b BoolField[T]) Equal(other T) BoolField[T]
- func (b BoolField[T]) Label(label string) BoolField[T]
- func (b BoolField[T]) Message(message string) BoolField[T]
- func (b BoolField[T]) Using(rule Rule[T]) BoolField[T]
- type ConfigurationError
- type ContextRuleFunc
- type Errors
- type Field
- type Input
- type Issue
- type MapField
- func (b MapField[T]) Check(check func(context.Context, map[string]T) error) MapField[T]
- func (b MapField[T]) Each(fields func(string, T) []Field) MapField[T]
- func (b MapField[T]) HasKey(key string) MapField[T]
- func (b MapField[T]) Label(label string) MapField[T]
- func (b MapField[T]) Len(length int) MapField[T]
- func (b MapField[T]) Max(max int) MapField[T]
- func (b MapField[T]) Message(message string) MapField[T]
- func (b MapField[T]) Min(min int) MapField[T]
- func (b MapField[T]) OnlyKeys(keys ...string) MapField[T]
- func (b MapField[T]) Required() MapField[T]
- func (b MapField[T]) RequiredIf(condition bool) MapField[T]
- func (b MapField[T]) Using(rule Rule[map[string]T]) MapField[T]
- type NumberField
- func (b NumberField[T]) Check(check func(context.Context, T) error) NumberField[T]
- func (b NumberField[T]) Equal(other T) NumberField[T]
- func (b NumberField[T]) GreaterThan(other T) NumberField[T]
- func (b NumberField[T]) In(values ...T) NumberField[T]
- func (b NumberField[T]) Label(label string) NumberField[T]
- func (b NumberField[T]) LessThan(other T) NumberField[T]
- func (b NumberField[T]) Max(max T) NumberField[T]
- func (b NumberField[T]) Message(message string) NumberField[T]
- func (b NumberField[T]) Min(min T) NumberField[T]
- func (b NumberField[T]) MultipleOf(divisor T) NumberField[T]
- func (b NumberField[T]) NotEqual(other T) NumberField[T]
- func (b NumberField[T]) NotIn(values ...T) NumberField[T]
- func (b NumberField[T]) Using(rule Rule[T]) NumberField[T]
- type Numeric
- type PresenceField
- func (b PresenceField[T]) Label(label string) PresenceField[T]
- func (b PresenceField[T]) Message(message string) PresenceField[T]
- func (b PresenceField[T]) Nullable() PresenceField[T]
- func (b PresenceField[T]) Required() PresenceField[T]
- func (b PresenceField[T]) RequiredIf(condition bool) PresenceField[T]
- type Rule
- type RuleFunc
- type RuleWithContext
- type SliceField
- func (b SliceField[T]) Check(check func(context.Context, []T) error) SliceField[T]
- func (b SliceField[T]) Contains(target T) SliceField[T]
- func (b SliceField[T]) Each(fields func(T) []Field) SliceField[T]
- func (b SliceField[T]) Label(label string) SliceField[T]
- func (b SliceField[T]) Len(length int) SliceField[T]
- func (b SliceField[T]) Max(max int) SliceField[T]
- func (b SliceField[T]) Message(message string) SliceField[T]
- func (b SliceField[T]) Min(min int) SliceField[T]
- func (b SliceField[T]) NotContains(target T) SliceField[T]
- func (b SliceField[T]) Required() SliceField[T]
- func (b SliceField[T]) RequiredIf(condition bool) SliceField[T]
- func (b SliceField[T]) Unique() SliceField[T]
- func (b SliceField[T]) Using(rule Rule[[]T]) SliceField[T]
- type StringField
- func (b StringField[T]) Check(check func(context.Context, T) error) StringField[T]
- func (b StringField[T]) Contains(text string) StringField[T]
- func (b StringField[T]) EndsWith(suffix string) StringField[T]
- func (b StringField[T]) Equal(other T) StringField[T]
- func (b StringField[T]) In(values ...T) StringField[T]
- func (b StringField[T]) IsASCII() StringField[T]
- func (b StringField[T]) IsAlpha() StringField[T]
- func (b StringField[T]) IsAlphanumeric() StringField[T]
- func (b StringField[T]) IsBase64() StringField[T]
- func (b StringField[T]) IsBase64URL() StringField[T]
- func (b StringField[T]) IsCIDR() StringField[T]
- func (b StringField[T]) IsDate(layout string) StringField[T]
- func (b StringField[T]) IsDateIn(layout string, location *time.Location) StringField[T]
- func (b StringField[T]) IsDigits() StringField[T]
- func (b StringField[T]) IsE164() StringField[T]
- func (b StringField[T]) IsEmail() StringField[T]
- func (b StringField[T]) IsHostname() StringField[T]
- func (b StringField[T]) IsIP() StringField[T]
- func (b StringField[T]) IsIPv4() StringField[T]
- func (b StringField[T]) IsIPv6() StringField[T]
- func (b StringField[T]) IsJSON() StringField[T]
- func (b StringField[T]) IsLowercase() StringField[T]
- func (b StringField[T]) IsMAC() StringField[T]
- func (b StringField[T]) IsULID() StringField[T]
- func (b StringField[T]) IsURL() StringField[T]
- func (b StringField[T]) IsUTF8() StringField[T]
- func (b StringField[T]) IsUUID() StringField[T]
- func (b StringField[T]) IsUUIDv4() StringField[T]
- func (b StringField[T]) IsUUIDv7() StringField[T]
- func (b StringField[T]) IsUppercase() StringField[T]
- func (b StringField[T]) Label(label string) StringField[T]
- func (b StringField[T]) Len(length int) StringField[T]
- func (b StringField[T]) Match(pattern *regexp.Regexp) StringField[T]
- func (b StringField[T]) Max(max int) StringField[T]
- func (b StringField[T]) Message(message string) StringField[T]
- func (b StringField[T]) Min(min int) StringField[T]
- func (b StringField[T]) NotBlank() StringField[T]
- func (b StringField[T]) NotContains(text string) StringField[T]
- func (b StringField[T]) NotEqual(other T) StringField[T]
- func (b StringField[T]) NotIn(values ...T) StringField[T]
- func (b StringField[T]) Required() StringField[T]
- func (b StringField[T]) RequiredIf(condition bool) StringField[T]
- func (b StringField[T]) StartsWith(prefix string) StringField[T]
- func (b StringField[T]) Using(rule Rule[T]) StringField[T]
- type TimeField
- func (b TimeField) After(other time.Time) TimeField
- func (b TimeField) Before(other time.Time) TimeField
- func (b TimeField) Check(check func(context.Context, time.Time) error) TimeField
- func (b TimeField) Equal(other time.Time) TimeField
- func (b TimeField) Label(label string) TimeField
- func (b TimeField) Max(max time.Time) TimeField
- func (b TimeField) Message(message string) TimeField
- func (b TimeField) Min(min time.Time) TimeField
- func (b TimeField) Required() TimeField
- func (b TimeField) RequiredIf(condition bool) TimeField
- func (b TimeField) Using(rule Rule[time.Time]) TimeField
- type Validator
- type ValueField
- type Violation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BoolField ¶
type BoolField[T ~bool] struct { // contains filtered or unexported fields }
BoolField is an immutable fluent chain for bool values.
func (BoolField[T]) Accepted ¶
Accepted requires true while ordinary boolean checks continue to accept false.
func (BoolField[T]) Label ¶
Label sets the human-readable field name without changing its output path.
type ConfigurationError ¶
ConfigurationError identifies a malformed chain or rule rather than invalid input.
func (*ConfigurationError) Error ¶
func (e *ConfigurationError) Error() string
Error describes the invalid rule configuration without printing submitted values.
type ContextRuleFunc ¶
ContextRuleFunc adapts a context-aware function into a reusable typed rule.
func (ContextRuleFunc[T]) Validate ¶
func (f ContextRuleFunc[T]) Validate(value T) error
Validate evaluates the rule with a background context.
func (ContextRuleFunc[T]) ValidateContext ¶
func (f ContextRuleFunc[T]) ValidateContext(ctx context.Context, value T) error
ValidateContext forwards the caller's context to the adapted function.
type Errors ¶
type Errors struct {
// contains filtered or unexported fields
}
Errors contains ordered field failures and supports errors.As.
type Field ¶
type Field interface {
// contains filtered or unexported methods
}
Field is a deferred validation operation constructed by a typed builder or group.
type Input ¶
type Input[T any] struct { // contains filtered or unexported fields }
Input preserves whether JSON supplied a value, null, or no property at all. Its zero value is absent; use json's omitzero option to omit absent properties. Decoding T uses json.Unmarshal, so enclosing decoder options do not propagate.
func (Input[T]) Get ¶
Get returns the supplied value and reports whether it is present and non-null.
func (Input[T]) IsPresent ¶
IsPresent reports whether a property was supplied, including explicit null.
func (Input[T]) MarshalJSON ¶
MarshalJSON emits null for absent or null inputs and otherwise encodes the value.
func (*Input[T]) UnmarshalJSON ¶
UnmarshalJSON replaces the input only after a complete successful decode.
type Issue ¶
type Issue struct {
Path string `json:"path"`
Code string `json:"code"`
Message string `json:"message"`
Parameters map[string]string `json:"parameters,omitempty"`
}
Issue describes a failed field without retaining its submitted value.
type MapField ¶
type MapField[T any] struct { // contains filtered or unexported fields }
MapField validates a borrowed string-keyed map with deterministic child paths.
func (MapField[T]) Each ¶
Each constructs key and value checks in sorted key order after parent constraints pass.
func (MapField[T]) Message ¶
Message customizes the preceding parent constraint while preserving its code.
func (MapField[T]) OnlyKeys ¶
OnlyKeys permits only the listed keys, copying configuration independently of the caller.
func (MapField[T]) RequiredIf ¶
RequiredIf enforces a nonempty map only when condition is true.
type NumberField ¶
type NumberField[T Numeric] struct { // contains filtered or unexported fields }
NumberField is an immutable fluent chain for number values.
func Number ¶
func Number[T Numeric](path string, value T) NumberField[T]
Number starts a deferred chain for a borrowed application value.
func (NumberField[T]) Check ¶
func (b NumberField[T]) Check(check func(context.Context, T) error) NumberField[T]
Check attaches a context-aware application check.
func (NumberField[T]) Equal ¶
func (b NumberField[T]) Equal(other T) NumberField[T]
Equal requires the other value without exposing it in error messages.
func (NumberField[T]) GreaterThan ¶
func (b NumberField[T]) GreaterThan(other T) NumberField[T]
GreaterThan requires a strict lower bound in the field's numeric type.
func (NumberField[T]) In ¶
func (b NumberField[T]) In(values ...T) NumberField[T]
In permits only finite listed values and owns its constraint slice.
func (NumberField[T]) Label ¶
func (b NumberField[T]) Label(label string) NumberField[T]
Label sets the human-readable field name without changing its output path.
func (NumberField[T]) LessThan ¶
func (b NumberField[T]) LessThan(other T) NumberField[T]
LessThan requires a strict upper bound in the field's numeric type.
func (NumberField[T]) Max ¶
func (b NumberField[T]) Max(max T) NumberField[T]
Max requires an inclusive upper bound in the field's exact numeric type.
func (NumberField[T]) Message ¶
func (b NumberField[T]) Message(message string) NumberField[T]
Message overrides the preceding rule message while preserving its code.
func (NumberField[T]) Min ¶
func (b NumberField[T]) Min(min T) NumberField[T]
Min requires an inclusive lower bound in the field's exact numeric type.
func (NumberField[T]) MultipleOf ¶
func (b NumberField[T]) MultipleOf(divisor T) NumberField[T]
MultipleOf requires an exact remainder of zero; floats use binary math.Mod semantics.
func (NumberField[T]) NotEqual ¶
func (b NumberField[T]) NotEqual(other T) NumberField[T]
NotEqual rejects the other finite value without exposing it in errors.
func (NumberField[T]) NotIn ¶
func (b NumberField[T]) NotIn(values ...T) NumberField[T]
NotIn rejects the finite listed values and owns its constraint slice.
func (NumberField[T]) Using ¶
func (b NumberField[T]) Using(rule Rule[T]) NumberField[T]
Using attaches a reusable validator for the exact value type.
type Numeric ¶
type Numeric interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64
}
Numeric permits all Go integer and floating-point types, including defined types.
type PresenceField ¶
type PresenceField[T any] struct { // contains filtered or unexported fields }
PresenceField validates an Input while preserving omitted and explicit-null states.
func Presence ¶
func Presence[T any](path string, input Input[T], build func(T) Field) PresenceField[T]
Presence defers child validation until input contains a non-null value. Use an empty child path to retain path, or a named child to append a segment.
func (PresenceField[T]) Label ¶
func (b PresenceField[T]) Label(label string) PresenceField[T]
Label sets the human-readable name for presence failures.
func (PresenceField[T]) Message ¶
func (b PresenceField[T]) Message(message string) PresenceField[T]
Message overrides the preceding presence rule message while preserving its code.
func (PresenceField[T]) Nullable ¶
func (b PresenceField[T]) Nullable() PresenceField[T]
Nullable permits explicit null without constructing child validation.
func (PresenceField[T]) Required ¶
func (b PresenceField[T]) Required() PresenceField[T]
Required requires a supplied, non-null value; zero values remain valid.
func (PresenceField[T]) RequiredIf ¶
func (b PresenceField[T]) RequiredIf(condition bool) PresenceField[T]
RequiredIf requires a supplied, non-null value when condition is true.
type Rule ¶
type Rule[T any] interface { // Validate returns nil, an explicit Violation, or an operational error. Validate(value T) error }
Rule validates a value using application-owned configuration and dependencies.
func UniqueBy ¶
func UniqueBy[T any, K comparable](key func(T) K) Rule[[]T]
UniqueBy requires distinct comparable keys without retaining keys in failures.
type RuleWithContext ¶
type RuleWithContext[T any] interface { Rule[T] // ValidateContext uses the evaluation context for dependent operations. ValidateContext(ctx context.Context, value T) error }
RuleWithContext propagates request cancellation to dependent operations.
type SliceField ¶
type SliceField[T any] struct { // contains filtered or unexported fields }
SliceField is an immutable fluent chain for slice values.
func Slice ¶
func Slice[T any](path string, value []T) SliceField[T]
Slice starts a deferred chain for a borrowed application value.
func (SliceField[T]) Check ¶
func (b SliceField[T]) Check(check func(context.Context, []T) error) SliceField[T]
Check attaches a context-aware application check.
func (SliceField[T]) Contains ¶
func (b SliceField[T]) Contains(target T) SliceField[T]
Contains requires an element equal under reflect.DeepEqual; the target value is borrowed.
func (SliceField[T]) Each ¶
func (b SliceField[T]) Each(fields func(T) []Field) SliceField[T]
Each lazily constructs child fields for each element after parent checks pass.
func (SliceField[T]) Label ¶
func (b SliceField[T]) Label(label string) SliceField[T]
Label sets the human-readable field name without changing its output path.
func (SliceField[T]) Len ¶
func (b SliceField[T]) Len(length int) SliceField[T]
Len requires exactly length elements.
func (SliceField[T]) Max ¶
func (b SliceField[T]) Max(max int) SliceField[T]
Max permits at most max elements.
func (SliceField[T]) Message ¶
func (b SliceField[T]) Message(message string) SliceField[T]
Message overrides the preceding rule message while preserving its code.
func (SliceField[T]) Min ¶
func (b SliceField[T]) Min(min int) SliceField[T]
Min requires at least min elements.
func (SliceField[T]) NotContains ¶
func (b SliceField[T]) NotContains(target T) SliceField[T]
NotContains rejects an element equal under reflect.DeepEqual; the target value is borrowed.
func (SliceField[T]) Required ¶
func (b SliceField[T]) Required() SliceField[T]
Required rejects empty and nil slices before evaluating child fields.
func (SliceField[T]) RequiredIf ¶
func (b SliceField[T]) RequiredIf(condition bool) SliceField[T]
RequiredIf applies a nonempty constraint only when condition is true.
func (SliceField[T]) Unique ¶
func (b SliceField[T]) Unique() SliceField[T]
Unique requires distinct Go-comparable elements; use UniqueBy for structs with slices or maps.
func (SliceField[T]) Using ¶
func (b SliceField[T]) Using(rule Rule[[]T]) SliceField[T]
Using attaches a reusable validator for the exact value type.
type StringField ¶
type StringField[T ~string] struct { // contains filtered or unexported fields }
StringField is an immutable fluent chain for string values.
func String ¶
func String[T ~string](path string, value T) StringField[T]
String starts a deferred chain for a borrowed application value.
func (StringField[T]) Check ¶
func (b StringField[T]) Check(check func(context.Context, T) error) StringField[T]
Check attaches a context-aware application check.
func (StringField[T]) Contains ¶
func (b StringField[T]) Contains(text string) StringField[T]
Contains requires the configured substring without modifying case or whitespace.
func (StringField[T]) EndsWith ¶
func (b StringField[T]) EndsWith(suffix string) StringField[T]
EndsWith requires a literal suffix.
func (StringField[T]) Equal ¶
func (b StringField[T]) Equal(other T) StringField[T]
Equal requires the other value without retaining it in failure details.
func (StringField[T]) In ¶
func (b StringField[T]) In(values ...T) StringField[T]
In permits only the given values and owns a copy of their slice.
func (StringField[T]) IsASCII ¶
func (b StringField[T]) IsASCII() StringField[T]
IsASCII requires nonempty ASCII text, including control bytes.
func (StringField[T]) IsAlpha ¶
func (b StringField[T]) IsAlpha() StringField[T]
IsAlpha requires nonempty ASCII letters.
func (StringField[T]) IsAlphanumeric ¶
func (b StringField[T]) IsAlphanumeric() StringField[T]
IsAlphanumeric requires nonempty ASCII letters and digits.
func (StringField[T]) IsBase64 ¶
func (b StringField[T]) IsBase64() StringField[T]
IsBase64 requires strict standard padded Base64 without whitespace.
func (StringField[T]) IsBase64URL ¶
func (b StringField[T]) IsBase64URL() StringField[T]
IsBase64URL requires strict padded or raw URL-safe Base64.
func (StringField[T]) IsCIDR ¶
func (b StringField[T]) IsCIDR() StringField[T]
IsCIDR requires an IP prefix without normalizing host bits.
func (StringField[T]) IsDate ¶
func (b StringField[T]) IsDate(layout string) StringField[T]
IsDate requires a value parseable with a Go time layout, using UTC for unzoned input.
func (StringField[T]) IsDateIn ¶
func (b StringField[T]) IsDateIn(layout string, location *time.Location) StringField[T]
IsDateIn interprets unzoned input in location without changing the supplied string.
func (StringField[T]) IsDigits ¶
func (b StringField[T]) IsDigits() StringField[T]
IsDigits requires nonempty ASCII decimal digits.
func (StringField[T]) IsE164 ¶
func (b StringField[T]) IsE164() StringField[T]
IsE164 requires international phone-number syntax, without assignment checks.
func (StringField[T]) IsEmail ¶
func (b StringField[T]) IsEmail() StringField[T]
IsEmail requires a bare ASCII mailbox with a dotted domain.
func (StringField[T]) IsHostname ¶
func (b StringField[T]) IsHostname() StringField[T]
IsHostname requires ASCII DNS labels, optionally ending in a root dot.
func (StringField[T]) IsIP ¶
func (b StringField[T]) IsIP() StringField[T]
IsIP requires an unzoned IP address literal.
func (StringField[T]) IsIPv4 ¶
func (b StringField[T]) IsIPv4() StringField[T]
IsIPv4 requires an IPv4 address literal.
func (StringField[T]) IsIPv6 ¶
func (b StringField[T]) IsIPv6() StringField[T]
IsIPv6 requires an unzoned IPv6 address literal.
func (StringField[T]) IsJSON ¶
func (b StringField[T]) IsJSON() StringField[T]
IsJSON requires any valid JSON document, including scalar values.
func (StringField[T]) IsLowercase ¶
func (b StringField[T]) IsLowercase() StringField[T]
IsLowercase requires valid UTF-8 with at least one cased letter and no uppercase or titlecase letters.
func (StringField[T]) IsMAC ¶
func (b StringField[T]) IsMAC() StringField[T]
IsMAC requires a 48-bit or 64-bit link-layer address.
func (StringField[T]) IsULID ¶
func (b StringField[T]) IsULID() StringField[T]
IsULID requires a case-insensitive 128-bit ULID.
func (StringField[T]) IsURL ¶
func (b StringField[T]) IsURL() StringField[T]
IsURL requires an absolute HTTP or HTTPS URL with a host.
func (StringField[T]) IsUTF8 ¶
func (b StringField[T]) IsUTF8() StringField[T]
IsUTF8 requires valid UTF-8, including empty text.
func (StringField[T]) IsUUID ¶
func (b StringField[T]) IsUUID() StringField[T]
IsUUID requires a canonical UUID, including nil and max UUIDs.
func (StringField[T]) IsUUIDv4 ¶
func (b StringField[T]) IsUUIDv4() StringField[T]
IsUUIDv4 requires a canonical version 4 UUID.
func (StringField[T]) IsUUIDv7 ¶
func (b StringField[T]) IsUUIDv7() StringField[T]
IsUUIDv7 requires a canonical version 7 UUID.
func (StringField[T]) IsUppercase ¶
func (b StringField[T]) IsUppercase() StringField[T]
IsUppercase requires valid UTF-8 with at least one cased letter and no lowercase or titlecase letters.
func (StringField[T]) Label ¶
func (b StringField[T]) Label(label string) StringField[T]
Label sets the human-readable field name without changing its output path.
func (StringField[T]) Len ¶
func (b StringField[T]) Len(length int) StringField[T]
Len requires exactly length Unicode code points.
func (StringField[T]) Match ¶
func (b StringField[T]) Match(pattern *regexp.Regexp) StringField[T]
Match requires a match against an already compiled, caller-owned expression.
func (StringField[T]) Max ¶
func (b StringField[T]) Max(max int) StringField[T]
Max permits at most max Unicode code points.
func (StringField[T]) Message ¶
func (b StringField[T]) Message(message string) StringField[T]
Message overrides the preceding rule message while preserving its code.
func (StringField[T]) Min ¶
func (b StringField[T]) Min(min int) StringField[T]
Min requires at least min Unicode code points.
func (StringField[T]) NotBlank ¶
func (b StringField[T]) NotBlank() StringField[T]
NotBlank rejects empty strings and strings containing only Unicode whitespace.
func (StringField[T]) NotContains ¶
func (b StringField[T]) NotContains(text string) StringField[T]
NotContains rejects the configured substring without exposing it in failures.
func (StringField[T]) NotEqual ¶
func (b StringField[T]) NotEqual(other T) StringField[T]
NotEqual rejects the other value without retaining it in failure details.
func (StringField[T]) NotIn ¶
func (b StringField[T]) NotIn(values ...T) StringField[T]
NotIn rejects the listed values and owns a copy of their slice.
func (StringField[T]) Required ¶
func (b StringField[T]) Required() StringField[T]
Required rejects an empty string before content rules run.
func (StringField[T]) RequiredIf ¶
func (b StringField[T]) RequiredIf(condition bool) StringField[T]
RequiredIf applies an emptiness check only when condition is true.
func (StringField[T]) StartsWith ¶
func (b StringField[T]) StartsWith(prefix string) StringField[T]
StartsWith requires a literal prefix.
func (StringField[T]) Using ¶
func (b StringField[T]) Using(rule Rule[T]) StringField[T]
Using attaches a reusable validator for the exact value type.
type TimeField ¶
type TimeField struct {
// contains filtered or unexported fields
}
TimeField is an immutable fluent chain for time instants.
func (TimeField) Equal ¶
Equal requires the same instant without exposing the expected value in failures.
func (TimeField) RequiredIf ¶
RequiredIf rejects the zero time when condition is true.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator is an immutable evaluation policy; its zero value uses package defaults. Rule and formatter callbacks retain application ownership and concurrency requirements.
func New ¶
func New() Validator
New creates a validator with first-violation-per-field collection and default messages.
func (Validator) CollectAll ¶
CollectAll collects all content failures per field; required failures still stop that field.
func (Validator) FormatMessages ¶
FormatMessages formats violations by path, code, and owned parameters, unless Message overrides it. The callback receives no submitted value and may provide application-localized messages.
func (Validator) StopOnFirstError ¶
StopOnFirstError stops the entire evaluation after its first input violation.
type ValueField ¶
type ValueField[T any] struct { // contains filtered or unexported fields }
ValueField is an immutable fluent chain for value values.
func Value ¶
func Value[T any](path string, value T) ValueField[T]
Value starts a deferred chain for a borrowed application value.
func (ValueField[T]) Check ¶
func (b ValueField[T]) Check(check func(context.Context, T) error) ValueField[T]
Check attaches a context-aware application check.
func (ValueField[T]) Label ¶
func (b ValueField[T]) Label(label string) ValueField[T]
Label sets the human-readable field name without changing its output path.
func (ValueField[T]) Message ¶
func (b ValueField[T]) Message(message string) ValueField[T]
Message overrides the preceding rule message while preserving its code.
func (ValueField[T]) Using ¶
func (b ValueField[T]) Using(rule Rule[T]) ValueField[T]
Using attaches a reusable validator for the exact value type.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
advanced
command
|
|
|
constraints
command
|
|
|
context
command
|
|
|
custom
command
|
|
|
domain
command
|
|
|
errors
command
|
|
|
formats
command
|
|
|
moreformats
command
|
|
|
nested
command
|
|
|
patch
command
|
|
|
policies
command
|
|
|
presence
command
|
|
|
quickstart
command
|
|
|
time
command
|
|
|
internal
|
|
|
formats
Package formats owns the checks behind fluent string format methods.
|
Package formats owns the checks behind fluent string format methods. |
|
violation
Package violation shares coded failures between validation and format rules.
|
Package violation shares coded failures between validation and format rules. |