Documentation
¶
Overview ¶
Package validation provides input validation utilities for API handlers.
Index ¶
- type FieldError
- type ValidationError
- type Validator
- func (v *Validator) AddError(field, message string)
- func (v *Validator) Email(field, value string)
- func (v *Validator) Error() error
- func (v *Validator) HasErrors() bool
- func (v *Validator) MaxLength(field, value string, max int)
- func (v *Validator) MinLength(field, value string, min int)
- func (v *Validator) NoControlChars(field, value string)
- func (v *Validator) NoDangerousChars(field, value string)
- func (v *Validator) NonNegative(field string, value int)
- func (v *Validator) NonNegativeFloat(field string, value float64)
- func (v *Validator) OneOf(field, value string, allowed []string)
- func (v *Validator) Positive(field string, value int)
- func (v *Validator) PositiveFloat(field string, value float64)
- func (v *Validator) Range(field string, value, min, max int)
- func (v *Validator) RangeFloat(field string, value, min, max float64)
- func (v *Validator) Required(field, value string)
- func (v *Validator) RequiredInt(field string, value int)
- func (v *Validator) RequiredInt64(field string, value int64)
- func (v *Validator) URL(field, value string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FieldError ¶
FieldError represents a validation error for a specific field.
type ValidationError ¶
type ValidationError struct {
Errors []FieldError `json:"errors"`
}
ValidationError represents a collection of validation errors.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error implements the error interface.
func (*ValidationError) HasErrors ¶
func (e *ValidationError) HasErrors() bool
HasErrors returns true if there are validation errors.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator collects validation errors.
func (*Validator) MaxLength ¶
MaxLength validates that a string doesn't exceed max length (in runes).
func (*Validator) NoControlChars ¶
NoControlChars validates that a string doesn't contain control characters (except common whitespace).
func (*Validator) NoDangerousChars ¶
NoDangerousChars validates that a string doesn't contain potentially dangerous characters. This is a basic sanitization check for fields that shouldn't contain special chars.
func (*Validator) NonNegative ¶
NonNegative validates that an int is non-negative (>= 0).
func (*Validator) NonNegativeFloat ¶
NonNegativeFloat validates that a float64 is non-negative (>= 0).
func (*Validator) PositiveFloat ¶
PositiveFloat validates that a float64 is positive (> 0).
func (*Validator) RangeFloat ¶
RangeFloat validates that a float64 is within range (inclusive).
func (*Validator) RequiredInt ¶
RequiredInt validates that an int field is not zero.
func (*Validator) RequiredInt64 ¶
RequiredInt64 validates that an int64 field is not zero.