validate

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPositive    = errors.New("validate: value must be positive")
	ErrBetween     = errors.New("validate: value must be between")
	ErrNegative    = errors.New("validate: value must be negative")
	ErrNonNegative = errors.New("validate: value must be non-negative")
	ErrMax         = errors.New("validate: value must be less or equal than")
	ErrMin         = errors.New("validate: value must be greater or equal than")
	ErrDivisorZero = errors.New("validate: divisor cannot be zero")
	ErrMultipleOf  = errors.New("validate: value must be multiple of")
)
View Source
var (
	ErrNotEmpty      = errors.New("validate: value cannot be empty")
	ErrLengthBetween = errors.New("validate: value's length must be between")
	ErrLengthMax     = errors.New("validate: value's length must be less or equal than")
	ErrLengthMin     = errors.New("validate: value's length must be greater or equal than")
)

Functions

func Between

func Between[T Number](lowerBound, upperBound T) func(T) error

Between validates if a value is within the specified lower and upper bounds (inclusive).

func LengthBetween added in v1.2.5

func LengthBetween(lowerBound, upperBound int) func(string) error

LengthBetween validates if a string's length is between the specified bounds (inclusive).

func LengthMax added in v1.2.5

func LengthMax(upperBound int) func(string) error

LengthMax ensures a string's length does not exceed the specified upperBound.

func LengthMin added in v1.2.5

func LengthMin(lowerBound int) func(string) error

LengthMin ensures a string's length is at least the specified lowerBound.

func Max

func Max[T Number](upperBound T) func(T) error

Max validates if a value is less than or equal to the specified upper bound.

func Min

func Min[T Number](lowerBound T) func(T) error

Min validates if a value is greater than or equal to the specified lower bound.

func MultipleOf

func MultipleOf[T Integer](divisor T) func(T) error

MultipleOf validates if a value is a multiple of the specified divisor.

func Negative

func Negative[T Number](value T) error

Negative checks if the given numeric value is negative.

func NonNegative

func NonNegative[T Number](value T) error

NonNegative validates that the provided numeric value is non-negative (including zero).

func NotEmpty added in v1.2.5

func NotEmpty(value string) error

func Positive

func Positive[T Number](value T) error

Positive checks if the provided value is positive (excluding zero).

Types

type Integer

type Integer interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~uintptr
}

type Number

type Number interface {
	Integer | ~float32 | ~float64
}

Jump to

Keyboard shortcuts

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