Documentation
¶
Index ¶
- type ValidationError
- func AlphanumericDashUnderscore(field, value string) *ValidationError
- func AlphanumericSpaceDashUnderscore(field, value string) *ValidationError
- func CronExpression(field, value string) *ValidationError
- func Email(field, value string) *ValidationError
- func FutureTime(field string, value time.Time) *ValidationError
- func IntRange(field string, value, min, max int) *ValidationError
- func MaxLength(field, value string, max int) *ValidationError
- func MaxSliceLength[T any](field string, slice []T, max int) *ValidationError
- func MinLength(field, value string, min int) *ValidationError
- func MinSliceLength[T any](field string, slice []T, min int) *ValidationError
- func ModelName(field, value string) *ValidationError
- func NoSQLInjection(field, value string) *ValidationError
- func NoXSS(field, value string) *ValidationError
- func NonNegativeInt(field string, value int) *ValidationError
- func OneOf(field, value string, allowed []string) *ValidationError
- func PastTime(field string, value time.Time) *ValidationError
- func PositiveInt(field string, value int) *ValidationError
- func Required(field, value string) *ValidationError
- func ULID(field, value string) *ValidationError
- func URL(field, value string) *ValidationError
- func UUID(field, value string) *ValidationError
- type ValidationErrors
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ValidationError ¶
type ValidationError struct {
Field string // The field that failed validation
Message string // Human-readable error message
Code string // Machine-readable error code (e.g., "required", "invalid_format")
}
ValidationError represents a validation failure with a helpful message.
func AlphanumericDashUnderscore ¶
func AlphanumericDashUnderscore(field, value string) *ValidationError
AlphanumericDashUnderscore validates that a string contains only alphanumeric characters, dashes, and underscores.
func AlphanumericSpaceDashUnderscore ¶
func AlphanumericSpaceDashUnderscore(field, value string) *ValidationError
AlphanumericSpaceDashUnderscore validates that a string contains only alphanumeric characters, spaces, dashes, and underscores.
func CronExpression ¶
func CronExpression(field, value string) *ValidationError
CronExpression validates that a string is a valid cron expression.
func Email ¶
func Email(field, value string) *ValidationError
Email validates that a string is a valid email address.
func FutureTime ¶
func FutureTime(field string, value time.Time) *ValidationError
FutureTime validates that a time is in the future.
func IntRange ¶
func IntRange(field string, value, min, max int) *ValidationError
IntRange validates that an integer is within the specified range (inclusive).
func MaxLength ¶
func MaxLength(field, value string, max int) *ValidationError
MaxLength validates that a string does not exceed the maximum length.
func MaxSliceLength ¶
func MaxSliceLength[T any](field string, slice []T, max int) *ValidationError
MaxSliceLength validates that a slice does not exceed the maximum length.
func MinLength ¶
func MinLength(field, value string, min int) *ValidationError
MinLength validates that a string meets the minimum length.
func MinSliceLength ¶
func MinSliceLength[T any](field string, slice []T, min int) *ValidationError
MinSliceLength validates that a slice meets the minimum length.
func ModelName ¶
func ModelName(field, value string) *ValidationError
ModelName validates that a string is a valid AI model name.
func NoSQLInjection ¶
func NoSQLInjection(field, value string) *ValidationError
NoSQLInjection validates that a string doesn't contain SQL injection patterns. This is a defense-in-depth measure; parameterized queries are still required.
func NoXSS ¶
func NoXSS(field, value string) *ValidationError
NoXSS validates that a string doesn't contain XSS patterns. This is a defense-in-depth measure; proper output encoding is still required.
func NonNegativeInt ¶
func NonNegativeInt(field string, value int) *ValidationError
NonNegativeInt validates that an integer is non-negative (>= 0).
func OneOf ¶
func OneOf(field, value string, allowed []string) *ValidationError
OneOf validates that a string is one of the allowed values.
func PastTime ¶
func PastTime(field string, value time.Time) *ValidationError
PastTime validates that a time is in the past.
func PositiveInt ¶
func PositiveInt(field string, value int) *ValidationError
PositiveInt validates that an integer is positive (> 0).
func Required ¶
func Required(field, value string) *ValidationError
Required validates that a string field is not empty.
func ULID ¶
func ULID(field, value string) *ValidationError
ULID validates that a string is a valid ULID.
func URL ¶
func URL(field, value string) *ValidationError
URL validates that a string is a valid HTTP/HTTPS URL.
func UUID ¶
func UUID(field, value string) *ValidationError
UUID validates that a string is a valid UUID v4.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error implements the error interface.
type ValidationErrors ¶
type ValidationErrors []ValidationError
ValidationErrors represents multiple validation failures.
func (ValidationErrors) Error ¶
func (errs ValidationErrors) Error() string
Error implements the error interface.
func (ValidationErrors) HasErrors ¶
func (errs ValidationErrors) HasErrors() bool
HasErrors returns true if there are any validation errors.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator is a helper type for chaining multiple validations.
func (*Validator) Add ¶
func (v *Validator) Add(err *ValidationError) *Validator
Add adds a validation error if it's not nil.