validators

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package validators provides type-specific validation functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildIntValidator

func BuildIntValidator(
	iv *IntValidators, rules []string, intType string,
) (func(any) error, error)

BuildIntValidator builds an integer validator from tokens. rules[0] == "int" or "int64".

func BuildSliceValidator

func BuildSliceValidator(
	sv *SliceValidators, rules []string,
) (func(any) error, error)

BuildSliceValidator builds a composite slice validator from tag tokens. Example: "slice;min=1;max=5".

func BuildStringValidator

func BuildStringValidator(
	sv *StringValidators, rules []string,
) (func(any) error, error)

BuildStringValidator builds a composite string validator from tokens. Expected tag: "string;min=3;max=10;regex=^a.*z$".

Types

type BoolValidator

type BoolValidator func(b bool) error

BoolValidator is a function that validates a bool.

type BoolValidators

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

BoolValidators provides boolean validation methods.

func NewBoolValidators

func NewBoolValidators(t translator.Translator) *BoolValidators

NewBoolValidators creates a new BoolValidators instance.

func (*BoolValidators) WithBool

func (bv *BoolValidators) WithBool(validators ...BoolValidator) func(value any) error

WithBool is a function that validates a bool.

type IntValidator

type IntValidator func(int64) error

IntValidator defines a function that validates an int64.

type IntValidators

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

IntValidators provides integer validation methods.

func NewIntValidators

func NewIntValidators(
	t translator.Translator,
) *IntValidators

func (*IntValidators) MaxInt

func (iv *IntValidators) MaxInt(max int64) IntValidator

func (*IntValidators) MinInt

func (iv *IntValidators) MinInt(min int64) IntValidator

func (*IntValidators) WithInt

func (iv *IntValidators) WithInt(
	validators ...IntValidator,
) func(any) error

WithInt applies IntValidators converting the value to int64 first.

func (*IntValidators) WithInt64

func (iv *IntValidators) WithInt64(
	validators ...IntValidator,
) func(any) error

WithInt64 applies IntValidators requiring exactly int64.

type SliceValidator

type SliceValidator func([]any) error

SliceValidator validates a slice presented as []any.

type SliceValidators

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

func NewSliceValidators

func NewSliceValidators(
	t translator.Translator,
) *SliceValidators

func (*SliceValidators) ForEach

func (sv *SliceValidators) ForEach(
	elementValidator func(any) error,
) SliceValidator

ForEach applies an element validator to every element in the slice.

func (*SliceValidators) MaxSliceLength

func (sv *SliceValidators) MaxSliceLength(n int) SliceValidator

func (*SliceValidators) MinSliceLength

func (sv *SliceValidators) MinSliceLength(n int) SliceValidator

func (*SliceValidators) SliceLength

func (sv *SliceValidators) SliceLength(n int) SliceValidator

func (*SliceValidators) WithSlice

func (sv *SliceValidators) WithSlice(
	validators ...SliceValidator,
) func(any) error

WithSlice applies validators to any slice type via reflection.

type StringValidator

type StringValidator func(string) error

StringValidator defines a function that validates a string.

type StringValidators

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

StringValidators provides string validation methods.

func NewStringValidators

func NewStringValidators(
	t translator.Translator,
) *StringValidators

NewStringValidators creates a new StringValidators instance.

func (*StringValidators) Email

func (sv *StringValidators) Email() StringValidator

func (*StringValidators) Length

func (sv *StringValidators) Length(n int) StringValidator

Length returns a validator that checks for exact length.

func (*StringValidators) MaxLength

func (sv *StringValidators) MaxLength(n int) StringValidator

func (*StringValidators) MinLength

func (sv *StringValidators) MinLength(n int) StringValidator

func (*StringValidators) OneOf

func (sv *StringValidators) OneOf(
	values ...string,
) StringValidator

func (*StringValidators) Regex

func (sv *StringValidators) Regex(pattern string) StringValidator

Regex returns a validator that ensures the string matches the pattern.

func (*StringValidators) WithString

func (sv *StringValidators) WithString(
	validators ...StringValidator,
) func(any) error

WithString applies a series of string validators to a value.

Jump to

Keyboard shortcuts

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