validation

package
v1.29.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

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 NewValidator

func NewValidator() *Validator

NewValidator creates a new Validator instance.

func (*Validator) Add

func (v *Validator) Add(err *ValidationError) *Validator

Add adds a validation error if it's not nil.

func (*Validator) Errors

func (v *Validator) Errors() error

Errors returns all validation errors, or nil if there are none.

func (*Validator) HasErrors

func (v *Validator) HasErrors() bool

HasErrors returns true if there are any validation errors.

Jump to

Keyboard shortcuts

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