validat

package
v2.11.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnableRegexpCache added in v2.10.0

func EnableRegexpCache(cache lru.Interface[string, *regexp.Regexp])

Types

type IntegerOrString added in v2.10.0

type IntegerOrString interface {
	constraints.Integer | ~string
}

type RangeMode

type RangeMode int
const (
	GtAndLte  RangeMode = iota // min < x && x <= max
	GtAndLt                    // min < x && x < max
	GteAndLte                  // min <= x && x <= max
	GteAndLt                   // min <= x && x < max
)

type RegexpOrString added in v2.10.0

type RegexpOrString interface {
	*regexp.Regexp | string
}

type Result

type Result struct {
	Data       ezmap.Map
	ErrDetails []any
}

func Validate

func Validate(ctx context.Context, rules ...Rule) (*Result, error)

type Rule

type Rule interface {
	Validate(ctx context.Context, result *Result) (any, error)
}

type RuleFunc

type RuleFunc func(ctx context.Context, result *Result) (any, error)

func GreaterThanZero

func GreaterThanZero[T IntegerOrString](name string, value T, save bool) RuleFunc

func InRange

func InRange[T constraints.Integer](name string, min, max T, value T) RuleFunc

func InRangeMode

func InRangeMode[T constraints.Integer](name string, mode RangeMode, min, max T, value T) RuleFunc

func LessThanOrEqual

func LessThanOrEqual[T constraints.Integer](name string, limit, value T) RuleFunc

func MatchRegexp added in v2.10.0

func MatchRegexp[T RegexpOrString](name string, pattern T, value string) RuleFunc

func NotNil

func NotNil(name string, value any) RuleFunc

func ParseStrsToInt64Map added in v2.10.0

func ParseStrsToInt64Map(name string, values []string) RuleFunc

func ParseStrsToInt64Slice added in v2.10.0

func ParseStrsToInt64Slice(name string, values []string) RuleFunc

func (RuleFunc) Validate

func (f RuleFunc) Validate(ctx context.Context, result *Result) (any, error)

type ValidationError added in v2.10.0

type ValidationError struct {
	Name string
	Err  error
}

func (*ValidationError) Error added in v2.10.0

func (e *ValidationError) Error() string

func (*ValidationError) Unwrap added in v2.10.0

func (e *ValidationError) Unwrap() error

Jump to

Keyboard shortcuts

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