Documentation
¶
Overview ¶
Package validation provides rules-based output validation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CustomRule ¶
type CustomRule struct {
// contains filtered or unexported fields
}
CustomRule allows custom validation logic.
func Custom ¶
func Custom(name, field string, check func(value any) (valid bool, message string)) *CustomRule
Custom creates a custom validation rule.
func (*CustomRule) Name ¶
func (r *CustomRule) Name() string
func (*CustomRule) Validate ¶
func (r *CustomRule) Validate(value any) *ValidationError
type EnumRule ¶
type EnumRule struct {
// contains filtered or unexported fields
}
EnumRule validates that a value is in a set of allowed values.
func (*EnumRule) Validate ¶
func (r *EnumRule) Validate(value any) *ValidationError
type LengthRule ¶
type LengthRule struct {
// contains filtered or unexported fields
}
LengthRule validates string or slice length.
func Length ¶
func Length(field string, min, max int) *LengthRule
Length creates a length validation rule.
func (*LengthRule) Name ¶
func (r *LengthRule) Name() string
func (*LengthRule) Validate ¶
func (r *LengthRule) Validate(value any) *ValidationError
type RangeRule ¶
type RangeRule struct {
// contains filtered or unexported fields
}
RangeRule validates that a numeric value is within a range.
func (*RangeRule) Validate ¶
func (r *RangeRule) Validate(value any) *ValidationError
type RegexRule ¶
type RegexRule struct {
// contains filtered or unexported fields
}
RegexRule validates a string against a regex pattern.
func (*RegexRule) Validate ¶
func (r *RegexRule) Validate(value any) *ValidationError
type RequiredRule ¶
type RequiredRule struct {
// contains filtered or unexported fields
}
RequiredRule checks that a value is not nil or empty.
func (*RequiredRule) Name ¶
func (r *RequiredRule) Name() string
func (*RequiredRule) Validate ¶
func (r *RequiredRule) Validate(value any) *ValidationError
type Result ¶
type Result struct {
Valid bool
Errors []*ValidationError
Warnings []*ValidationError
}
Result contains validation results.
type Rule ¶
type Rule interface {
// Name returns the rule identifier.
Name() string
// Validate checks the value and returns an error if invalid.
Validate(value any) *ValidationError
}
Rule defines a validation rule interface.
type RuleSet ¶
type RuleSet struct {
// contains filtered or unexported fields
}
RuleSet composes multiple rules.
func NewRuleSet ¶
NewRuleSet creates a new rule set.
func (*RuleSet) Validate ¶
func (rs *RuleSet) Validate(value any) []*ValidationError
Validate runs all rules and returns all errors.
func (*RuleSet) ValidateFirst ¶
func (rs *RuleSet) ValidateFirst(value any) *ValidationError
ValidateFirst runs rules until first error.
type ValidationError ¶
ValidationError represents a validation failure.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator validates values against rule sets.
func NewValidator ¶
NewValidator creates a new validator.
func (*Validator) WithWarnings ¶
WithWarnings adds warning rules (non-fatal).