validation

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

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

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 CustomInt

func CustomInt(fn func(int) bool, message string) validation.Rule[int]

CustomInt allows defining custom validation logic for integers.

func CustomString

func CustomString(fn func(string) bool, message string) validation.Rule[string]

CustomString allows defining custom validation logic for strings.

func Email

func Email() validation.Rule[string]

Email validates email format (simple validation).

func Max

func Max(maximum int) validation.Rule[int]

Max validates maximum integer value.

func MaxLength

func MaxLength(maximum int) validation.Rule[string]

MaxLength validates maximum string length.

func Min

func Min(minimum int) validation.Rule[int]

Min validates minimum integer value.

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.

Jump to

Keyboard shortcuts

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