Documentation
¶
Overview ¶
Package validation provides advanced validation constructors and rules for complex validation scenarios. It offers type-safe validation with generic support and integration with the govalin validation system.
Index ¶
- func Custom[T any](fn func(T) bool, message string) validation.Rule[T]
- func CustomInt(fn func(int) bool, message string) validation.Rule[int]
- func CustomString(fn func(string) bool, message string) validation.Rule[string]
- func Email() validation.Rule[string]
- func Max(maximum int) validation.Rule[int]
- func MaxLength(maximum int) validation.Rule[string]
- func Min(minimum int) validation.Rule[int]
- func MinLength(minimum int) validation.Rule[string]
- func NewIntValidator() *validation.Validator[int]
- func NewStringValidator() *validation.Validator[string]
- func NewStructValidator() *validation.StructValidator
- func Range(minimum, maximum int) validation.Rule[int]
- func Required() validation.Rule[string]
- func Validate[T any]() *validation.Validator[T]
- func WithTypedCustom[T any, V interface{ ... }](v V, validatorFn func(T) bool, message string) V
- type TypedValidator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Custom ¶
func Custom[T any](fn func(T) bool, message string) validation.Rule[T]
Custom creates a custom validation rule for any type T - use with caution.
func CustomString ¶
CustomString allows defining custom validation logic for strings.
func MaxLength ¶
func MaxLength(maximum int) validation.Rule[string]
MaxLength validates maximum string length.
func MinLength ¶
func MinLength(minimum int) validation.Rule[string]
MinLength validates minimum string length.
func NewIntValidator ¶
func NewIntValidator() *validation.Validator[int]
NewIntValidator provides type-safe integer validation.
func NewStringValidator ¶
func NewStringValidator() *validation.Validator[string]
NewStringValidator provides type-safe string validation.
func NewStructValidator ¶
func NewStructValidator() *validation.StructValidator
NewStructValidator provides validation for struct fields.
func Range ¶
func Range(minimum, maximum int) validation.Rule[int]
Range validates integer is within range.
func Required ¶
func Required() validation.Rule[string]
Required validates that a string is not empty.
func Validate ¶
func Validate[T any]() *validation.Validator[T]
Validate creates a validator for any type T - use with caution as it may cause build issues on older Go versions.
func WithTypedCustom ¶
func WithTypedCustom[T any, V interface{ AddRule(func(interface{}) error) }]( v V, validatorFn func(T) bool, message string, ) V
WithTypedCustom adds a type-safe custom validation rule for the entire body using a helper function This function works with any type that has an AddRule method Deprecated: Use WithTyped().Custom(...).Get() for curryable validation.
Types ¶
type TypedValidator ¶
type TypedValidator[T any] struct { // contains filtered or unexported fields }
TypedValidator provides a curryable typed validator.
func WithTyped ¶
func WithTyped[T any, V interface { AddRule(func(interface{}) error) Get() error }](v V) *TypedValidator[T]
WithTyped creates a curryable typed validator for type-safe custom validation.
func (*TypedValidator[T]) Custom ¶
func (tv *TypedValidator[T]) Custom(validatorFn func(T) bool, message string) *TypedValidator[T]
Custom adds a type-safe custom validation rule that can be chained.
func (*TypedValidator[T]) Get ¶
func (tv *TypedValidator[T]) Get() error
Get executes all validation rules and returns any validation error.