validation

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Check     = rule("check")
	RoleRange = rule("rolerange")
)
View Source
var ErrInvalidInput = fmt.Errorf("invalid input")

Functions

func NewTool

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

Types

type Client

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

func NewClient

func NewClient() Client

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 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 not be nil or zero.

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