validation

package
v0.1.324 Latest Latest
Warning

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

Go to latest
Published: May 21, 2025 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Validate   = rule("validate")
	RoleRange  = rule("rolerange")
	NonNilPtr  = rule("nnpt")
	NonZero    = rule("nz")
	IsUTC      = rule("utc")
	DayRange   = rule("dayrange")
	MonthRange = rule("monthrange")
)

Functions

This section is empty.

Types

type Client

type Client interface {
	Register(ctx context.Context, r Rule, fn ValidatorFunc) error
	Validate(ctx context.Context, key string, v any) error
}

func NewClient

func NewClient() Client

type DefaultTool added in v0.1.11

type DefaultTool struct {
	T *contract.Tool[Client]
}

func NewTool

func NewTool(client Client, opts contract.ToolOptions[Client]) *DefaultTool

func (*DefaultTool) Register added in v0.1.11

func (d *DefaultTool) Register(ctx context.Context, r Rule, fn ValidatorFunc) error

Register registers a validator function with the given rule.

func (*DefaultTool) Validate added in v0.1.11

func (d *DefaultTool) Validate(ctx context.Context, key string, v any) error

Validate runs all registered validators on a struct tagged with the provided tag key.

type RangeOption

type RangeOption func(*RangeOptions)

func WithMax

func WithMax(max float64) RangeOption

func WithMin

func WithMin(min float64) RangeOption

type RangeOptions

type RangeOptions struct {
	Min float64
	Max float64
}

func ApplyRangeOptions

func ApplyRangeOptions(opts *RangeOptions, modifiers ...RangeOption) RangeOptions

type RequireOption

type RequireOption func(*RequireOptions)

func WithNonNilPointer

func WithNonNilPointer() RequireOption

func WithNonZeroValue

func WithNonZeroValue() RequireOption

type RequireOptions

type RequireOptions struct {
	NonNilPointer bool
	NonZeroValue  bool
}

func ApplyRequireOptions

func ApplyRequireOptions(opts *RequireOptions, modifiers ...RequireOption) RequireOptions

type Rule

type Rule = string

type Tool added in v0.1.245

type Tool interface {
	Client
}

type ValidatorFunc

type ValidatorFunc func(v reflect.Value, field string) error

func InRange

func InRange(opts RangeOptions) ValidatorFunc

InRange returns a ValidatorFunc that requires the value to be within the specified range.

func Require

func Require(opts RequireOptions) ValidatorFunc

Require returns a ValidatorFunc that requires the value to meet the specified conditions.

func RequireBCP47

func RequireBCP47() ValidatorFunc

RequireBCP47 returns a ValidatorFunc that requires the value to be a valid BCP47 language tag.

func RequireE164Phone

func RequireE164Phone() ValidatorFunc

RequireE164Phone returns a ValidatorFunc that requires the value to be a valid E.164 phone number.

func RequireISOCurrency

func RequireISOCurrency() ValidatorFunc

RequireISOCurrency returns a ValidatorFunc that requires the value to be a valid ISO 4217 currency code.

func RequireUTCDate

func RequireUTCDate() ValidatorFunc

RequireUTCDate returns a ValidatorFunc that requires the value to be a valid UTC date.

Jump to

Keyboard shortcuts

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