validators

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValidatorAlreadyExists = errors.New("validator already exists")
)

Static error variables

Functions

func GetAny

func GetAny(name string) (any, bool)

GetAny retrieves a validator by name without type checking

func ListValidators

func ListValidators() []string

ListValidators returns all registered validator names

func Register

func Register[T any](validator ZodValidator[T]) error

Register registers a validator instance by its name

func ToCheckFn

func ToCheckFn[T any](validator ZodValidator[T], ctx *core.ParseContext) core.ZodCheckFn

ToCheckFn converts a ZodValidator to a ZodCheckFn for use with GoZod schemas

func ToCheckFnWithParam

func ToCheckFnWithParam[T any](validator ZodParameterizedValidator[T], param string, ctx *core.ParseContext) core.ZodCheckFn

ToCheckFnWithParam converts a ZodParameterizedValidator to a ZodCheckFn with parameter

func ToRefineFn

func ToRefineFn[T any](validator ZodValidator[T]) core.ZodRefineFn[T]

ToRefineFn converts a ZodValidator to a ZodRefineFn for use with GoZod schemas

Types

type ValidatorRegistry

type ValidatorRegistry struct {
	// contains filtered or unexported fields
}

ValidatorRegistry manages registered validators

type ZodDetailedValidator

type ZodDetailedValidator[T any] interface {
	ZodValidator[T]

	// ValidateDetail performs detailed validation with access to ParsePayload
	ValidateDetail(value T, payload *core.ParsePayload)
}

ZodDetailedValidator extends ZodValidator for complex validation scenarios

type ZodParameterizedValidator

type ZodParameterizedValidator[T any] interface {
	ZodValidator[T]

	// ValidateParam performs validation with a parameter
	ValidateParam(value T, param string) bool

	// ErrorMessageWithParam returns an error message with parameter context
	ErrorMessageWithParam(ctx *core.ParseContext, param string) string
}

ZodParameterizedValidator extends ZodValidator to support parameters

type ZodValidator

type ZodValidator[T any] interface {
	// Validate performs basic validation on the value
	Validate(value T) bool

	// Name returns the validator's unique name
	Name() string

	// ErrorMessage returns a basic error message for validation failures
	ErrorMessage(ctx *core.ParseContext) string
}

ZodValidator represents a basic validator interface for type T

func Get

func Get[T any](name string) (ZodValidator[T], bool)

Get retrieves a validator by name and type

Jump to

Keyboard shortcuts

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