valgopt

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: MIT Imports: 10 Imported by: 0

README

Valgopt

⚠️ Warning: This project is being tested so it's not ready for production use.

Valgopt provides a set of validators for the Valgo validation library that work seamlessly with optional value types from the Opt library.

This project extends Valgo's validation capabilities by providing validators specifically designed for Opt's optional types: omit.Val[T], null.Val[T], and omitnull.Val[T]. These validators replicate the functionality of Valgo's original validators while properly handling the optional nature of these types, allowing you to validate optional values in your Go applications with the same expressive and type-safe API that Valgo provides.

Quick Example

package main

import (
	"fmt"
	
	"github.com/aarondl/opt/null"
	"github.com/aarondl/opt/omit"
	"github.com/aarondl/opt/omitnull"
	"github.com/cohesivestack/valgo"
	"github.com/cohesivestack/valgopt"
)

type User struct {
	Age        null.Val[int]      // nullable field
	Score      omit.Val[int]      // omitted when empty
	Level      omitnull.Val[int]  // omitted when empty or null
}

func validateUser(user User) *valgo.ValidationSession {
	return valgo.New().
		Is(valgopt.NullInt(user.Age, "age").GreaterThan(0).LessThan(150)).
		Is(valgopt.OmitInt(user.Score, "score").GreaterOrEqualTo(0).LessOrEqualTo(100)).
		Is(valgopt.OmitNullInt(user.Level, "level").GreaterThan(0).LessOrEqualTo(10))
}

func main() {
	// Example 1: Valid user
	user1 := User{
		Age:   null.New(25),
		Score: omit.New(85),
		Level: omitnull.New(5),
	}
	
	validation := validateUser(user1)
	if validation.Valid() {
		fmt.Println("User is valid!")
	} else {
		fmt.Println("Validation errors:", validation.Errors())
	}
	
	// Example 2: Invalid user
	user2 := User{
		Age:   null.New(200),  // Invalid: too old
		Score: omit.New(150),  // Invalid: exceeds maximum
		Level: omitnull.New(15), // Invalid: exceeds maximum
	}
	
	validation = validateUser(user2)
	if !validation.Valid() {
		fmt.Println("Validation errors:")
		for field, errors := range validation.Errors() {
			fmt.Printf("  %s: %v\n", field, errors)
		}
	}
	
	// Example 3: Optional values (null/empty values are skipped)
	user3 := User{
		Age:   null.Val[int]{},   // null - validation skipped
		Score: omit.Val[int]{},   // empty - validation skipped
		Level: omitnull.Val[int]{}, // empty - validation skipped
	}
	
	validation = validateUser(user3)
	// All validations are skipped for null/empty optional values
	fmt.Println("Optional values validation:", validation.Valid())
}

This example demonstrates:

  • Using NullInt for nullable integer values
  • Using OmitInt for integer values that are omitted when empty
  • Using OmitNullInt for integer values that are omitted when empty or null
  • How validators automatically skip validation for null/empty optional values
  • The same expressive API as Valgo's standard validators

License

Copyright © 2025 Carlos Forero

Valgopt is released under the MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TypeNumber

type TypeNumber interface {
	~int |
		~int8 |
		~int16 |
		~int32 |
		~int64 |
		~uint |
		~uint8 |
		~uint16 |
		~uint32 |
		~uint64 |
		~float32 |
		~float64
}

Custom generic type covering all numeric types. This type is used as the value type in ValidatorOmitNumber.

type ValidatorNullAny

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

The ValidatorNullAny provides functions for setting validation rules for nullable value types from the Opt library (null.Val[any]). These validators properly handle the nullable nature of null.Val[any] types, only validating when a value is not null.

func NullAny

func NullAny(value null.Val[any], nameAndTitle ...string) *ValidatorNullAny

Receives a nullable value (null.Val[any]) to validate.

The value can be any type wrapped in null.Val[any]. The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A value_%N pattern is used as a name in the error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name phone_number will be humanized as Phone Number.

func (*ValidatorNullAny) Context

func (validator *ValidatorNullAny) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorNullAny) EqualTo

func (validator *ValidatorNullAny) EqualTo(value any, template ...string) *ValidatorNullAny

Validate if a nullable value is equal to another. This function uses reflection to compare values, which works for all types including incomparable types. The validation only passes if the value is not null and equal to the provided value. For example:

status := null.Val[any]{}
status.Set("running")
Is(v.NullAny(status).EqualTo("running"))

DEPRECATED: 'any' is not safely comparable. Use the NullTyped validator instead. This function will be removed in Valgo v1.0.0.

func (*ValidatorNullAny) Nil

func (validator *ValidatorNullAny) Nil(template ...string) *ValidatorNullAny

Validate if a nullable value is nil. The validation passes if: - The null.Val itself is null (not set), OR - The value inside is nil (for nil-able types like pointers, slices, maps, etc.)

For example:

nullVal := null.Val[any]{}
Is(v.NullAny(nullVal).Nil())

var status *string
val := null.Val[any]{}
val.Set(status)
Is(v.NullAny(val).Nil())

func (*ValidatorNullAny) Not

func (validator *ValidatorNullAny) Not() *ValidatorNullAny

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with the EqualTo() function
val := null.Val[any]{}
val.Set("a")
Is(v.NullAny(val).Not().EqualTo("a")).Valid()

func (*ValidatorNullAny) Or

func (validator *ValidatorNullAny) Or() *ValidatorNullAny

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the value is equal to "test".
input := null.Val[any]{}
input.Set("test")
isValid := v.Is(v.NullAny(input).Passing(func(v any) bool { return v == nil }).Or().EqualTo("test")).Valid()

func (*ValidatorNullAny) Passing

func (validator *ValidatorNullAny) Passing(function func(v null.Val[any]) bool, template ...string) *ValidatorNullAny

Validate if a nullable value passes a custom function. The validation only passes if the value is not null and the custom function returns true. For example:

status := null.Val[any]{}
status.Set("")
Is(v.NullAny(status).Passing((v any) bool {
	return v == getNewStatus()
})

type ValidatorNullBoolean

type ValidatorNullBoolean[T ~bool] struct {
	// contains filtered or unexported fields
}

The ValidatorNullBoolean provides functions for setting validation rules for nullable boolean value types from the Opt library (null.Val[T]), or a custom type based on a bool. These validators properly handle the nullable nature of null.Val[T] types, only validating when a value is not null.

func NullBoolean

func NullBoolean[T ~bool](value null.Val[T], nameAndTitle ...string) *ValidatorNullBoolean[T]

Receives a nullable boolean value (null.Val[T]) to validate.

The value can also be a custom boolean type such as `type Active bool;`, wrapped in null.Val. The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func (*ValidatorNullBoolean[T]) Context

func (validator *ValidatorNullBoolean[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorNullBoolean[T]) EqualTo

func (validator *ValidatorNullBoolean[T]) EqualTo(value T, template ...string) *ValidatorNullBoolean[T]

Validate if a nullable boolean value is equal to another. The validation only passes if the value is not null and equal to the provided value. For example:

activated := null.Val[bool]{}
activated.Set(true)
Is(v.NullBoolean(activated).EqualTo(true))

func (*ValidatorNullBoolean[T]) False

func (validator *ValidatorNullBoolean[T]) False(template ...string) *ValidatorNullBoolean[T]

Validate if a nullable boolean value is false. The validation only passes if the value is not null and equal to false. For example:

activated := null.Val[bool]{}
activated.Set(false)
Is(v.NullBoolean(activated).False())

func (*ValidatorNullBoolean[T]) FalseOrNil

func (validator *ValidatorNullBoolean[T]) FalseOrNil(template ...string) *ValidatorNullBoolean[T]

Validate if a nullable boolean value is false or null. The validation passes if the value is null or (set and not null and equal to false).

For example:

activated := null.Val[bool]{}
activated.Set(false)
Is(v.NullBoolean(activated).FalseOrNil())

nullActivated := null.Val[bool]{}
Is(v.NullBoolean(nullActivated).FalseOrNil())

func (*ValidatorNullBoolean[T]) InSlice

func (validator *ValidatorNullBoolean[T]) InSlice(slice []T, template ...string) *ValidatorNullBoolean[T]

Validate if a nullable boolean value is present in a boolean slice. The validation only passes if the value is not null and found in the provided slice. For example:

activated := null.Val[bool]{}
activated.Set(false)
elements := []bool{true, false, true}
Is(v.NullBoolean(activated).InSlice(elements))

func (*ValidatorNullBoolean[T]) Nil

func (validator *ValidatorNullBoolean[T]) Nil(template ...string) *ValidatorNullBoolean[T]

Validate if a nullable boolean value is null. The validation only passes if the value is null.

For example:

nullActivated := null.Val[bool]{}
Is(v.NullBoolean(nullActivated).Nil())

func (*ValidatorNullBoolean[T]) Not

func (validator *ValidatorNullBoolean[T]) Not() *ValidatorNullBoolean[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because `Not()` inverts the boolean value associated with the True() function
activated := null.Val[bool]{}
activated.Set(true)
Is(v.NullBoolean(activated).Not().True()).Valid()

func (*ValidatorNullBoolean[T]) Or

func (validator *ValidatorNullBoolean[T]) Or() *ValidatorNullBoolean[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the input is equals false.
input := null.Val[bool]{}
input.Set(true)
isValid := v.Is(v.NullBoolean(input).False().Or().True()).Valid()

func (*ValidatorNullBoolean[T]) Passing

func (validator *ValidatorNullBoolean[T]) Passing(function func(v null.Val[T]) bool, template ...string) *ValidatorNullBoolean[T]

Validate if a nullable boolean value passes a custom function. The validation only passes if the value is not null and the custom function returns true. For example:

activated := null.Val[bool]{}
activated.Set(false)
Is(v.NullBoolean(activated).Passing((v bool) bool {
	return v == someBoolFunction()
})

func (*ValidatorNullBoolean[T]) True

func (validator *ValidatorNullBoolean[T]) True(template ...string) *ValidatorNullBoolean[T]

Validate if a nullable boolean value is true. The validation only passes if the value is not null and equal to true. For example:

activated := null.Val[bool]{}
activated.Set(true)
Is(v.NullBoolean(activated).True())

type ValidatorNullComparable

type ValidatorNullComparable[T comparable] struct {
	// contains filtered or unexported fields
}

The ValidatorNullComparable provides functions for setting validation rules for nullable comparable value types from the Opt library (null.Val[T]). T can be any Go type (pointer, struct, etc.) that is comparable. These validators properly handle the nullable nature of null.Val[T] types, only validating when a value is not null.

func NullComparable

func NullComparable[T comparable](value null.Val[T], nameAndTitle ...string) *ValidatorNullComparable[T]

Receives a nullable comparable value (null.Val[T]) to validate, where T must be comparable.

The value can be any Go type (pointer, struct, etc.) that is comparable, wrapped in null.Val. The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A value_%N pattern is used as a name in the error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name phone_number will be humanized as Phone Number.

Example:

status := null.Val[string]{}
status.Set("running")
v.Is(v.NullComparable(status).Not().EqualTo("stopped"))

func (*ValidatorNullComparable[T]) Context

func (validator *ValidatorNullComparable[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorNullComparable[T]) EqualTo

func (validator *ValidatorNullComparable[T]) EqualTo(value T, template ...string) *ValidatorNullComparable[T]

Validate if a nullable value is equal to another. This function internally uses the golang `==` operator. The validation only passes if the value is not null and equal to the provided value. For example:

status := null.Val[string]{}
status.Set("running")
Is(v.NullComparable(status).EqualTo("running"))

func (*ValidatorNullComparable[T]) InSlice

func (validator *ValidatorNullComparable[T]) InSlice(slice []T, template ...string) *ValidatorNullComparable[T]

Validate if a nullable value is present in a slice. The validation only passes if the value is not null and found in the provided slice. For example:

status := null.Val[string]{}
status.Set("idle")
validStatus := []string{"idle", "paused", "stopped"}
Is(v.NullComparable(status).InSlice(validStatus))

func (*ValidatorNullComparable[T]) Nil

func (validator *ValidatorNullComparable[T]) Nil(template ...string) *ValidatorNullComparable[T]

Validate if a nullable value is null. The validation only passes if the value is null.

For example:

nullStatus := null.Val[string]{}
Is(v.NullComparable(nullStatus).Nil())

func (*ValidatorNullComparable[T]) Not

func (validator *ValidatorNullComparable[T]) Not() *ValidatorNullComparable[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because `Not()` inverts the boolean value associated with `EqualTo()`
val := null.Val[string]{}
val.Set("a")
v.Is(v.NullComparable(val).Not().EqualTo("a")).Valid()

func (*ValidatorNullComparable[T]) Or

func (validator *ValidatorNullComparable[T]) Or() *ValidatorNullComparable[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the string is equals "running".
status := null.Val[string]{}
status.Set("running")
isValid := v.Is(v.NullComparable(status).EqualTo("paused").Or().EqualTo("running")).Valid()

func (*ValidatorNullComparable[T]) Passing

func (validator *ValidatorNullComparable[T]) Passing(function func(v null.Val[T]) bool, template ...string) *ValidatorNullComparable[T]

Validate if a nullable value passes a custom function. The function receives a typed T value, enabling compile-time type safety. The validation only passes if the value is not null and the custom function returns true.

For example:

type Status string
status := null.Val[Status]{}
status.Set(Status("running"))
isValid := v.Is(
  v.NullComparable(status).Passing(func(s Status) bool {
    return s == "running" || s == "paused"
  }),
).Valid()

type ValidatorNullFloat

type ValidatorNullFloat[T ~float32 | ~float64] struct {
	// contains filtered or unexported fields
}

The ValidatorNullFloat provides functions for setting validation rules for nullable float value types from the Opt library (null.Val[T]), or a custom type based on a float32 or float64. These validators properly handle the nullable nature of null.Val[T] types, only validating when a value is not null.

func NullFloat32

func NullFloat32[T ~float32](value null.Val[T], nameAndTitle ...string) *ValidatorNullFloat[T]

Receives a nullable float32 value (null.Val[T]) to validate.

The value can also be a custom float32 type such as type Price float32, wrapped in null.Val. The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func NullFloat64

func NullFloat64[T ~float64](value null.Val[T], nameAndTitle ...string) *ValidatorNullFloat[T]

Receives a nullable float64 value (null.Val[T]) to validate.

The value can also be a custom float64 type such as type Price float64, wrapped in null.Val. The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func (*ValidatorNullFloat[T]) Between

func (validator *ValidatorNullFloat[T]) Between(min T, max T, template ...string) *ValidatorNullFloat[T]

Validate if a nullable number is within a range (inclusive). The validation only passes if the value is not null and within the specified range. For example:

quantity := null.Val[float32]{}
quantity.Set(3.0)
Is(v.NullFloat32(quantity).Between(2.0, 6.0))

func (*ValidatorNullFloat[T]) Context

func (validator *ValidatorNullFloat[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorNullFloat[T]) EqualTo

func (validator *ValidatorNullFloat[T]) EqualTo(value T, template ...string) *ValidatorNullFloat[T]

Validate if a nullable numeric value is equal to another. This function internally uses the golang `==` operator. The validation only passes if the value is not null and equal to the provided value. For example:

quantity := null.Val[float32]{}
quantity.Set(2.0)
Is(v.NullFloat32(quantity).EqualTo(2.0))

func (*ValidatorNullFloat[T]) Finite

func (validator *ValidatorNullFloat[T]) Finite(template ...string) *ValidatorNullFloat[T]

Validate if a nullable numeric value is finite (not NaN and not infinite). The validation only passes if the value is not null and is finite.

For example:

quantity := null.Val[float32]{}
quantity.Set(3.14)
Is(v.NullFloat32(quantity).Finite())

func (*ValidatorNullFloat[T]) GreaterOrEqualTo

func (validator *ValidatorNullFloat[T]) GreaterOrEqualTo(value T, template ...string) *ValidatorNullFloat[T]

Validate if a nullable numeric value is greater than or equal to another. This function internally uses the golang `>=` operator. The validation only passes if the value is not null and greater than or equal to the provided value. For example:

quantity := null.Val[float32]{}
quantity.Set(3.0)
Is(v.NullFloat32(quantity).GreaterOrEqualTo(3.0))

func (*ValidatorNullFloat[T]) GreaterThan

func (validator *ValidatorNullFloat[T]) GreaterThan(value T, template ...string) *ValidatorNullFloat[T]

Validate if a nullable numeric value is greater than another. This function internally uses the golang `>` operator. The validation only passes if the value is not null and greater than the provided value. For example:

quantity := null.Val[float32]{}
quantity.Set(3.0)
Is(v.NullFloat32(quantity).GreaterThan(2.0))

func (*ValidatorNullFloat[T]) InSlice

func (validator *ValidatorNullFloat[T]) InSlice(slice []T, template ...string) *ValidatorNullFloat[T]

Validate if a nullable number is present in a numeric slice. The validation only passes if the value is not null and found in the provided slice. For example:

quantity := null.Val[float32]{}
quantity.Set(3.0)
validQuantities := []float32{1.0, 3.0, 5.0}
Is(v.NullFloat32(quantity).InSlice(validQuantities))

func (*ValidatorNullFloat[T]) Infinite

func (validator *ValidatorNullFloat[T]) Infinite(template ...string) *ValidatorNullFloat[T]

Validate if a nullable numeric value is infinite (positive or negative infinity). The validation only passes if the value is not null and is infinite.

For example:

quantity := null.Val[float32]{}
quantity.Set(float32(math.Inf(1)))
Is(v.NullFloat32(quantity).Infinite())

func (*ValidatorNullFloat[T]) LessOrEqualTo

func (validator *ValidatorNullFloat[T]) LessOrEqualTo(value T, template ...string) *ValidatorNullFloat[T]

Validate if a nullable numeric value is less than or equal to another. This function internally uses the golang `<=` operator. The validation only passes if the value is not null and less than or equal to the provided value. For example:

quantity := null.Val[float32]{}
quantity.Set(2.0)
Is(v.NullFloat32(quantity).LessOrEqualTo(2.0))

func (*ValidatorNullFloat[T]) LessThan

func (validator *ValidatorNullFloat[T]) LessThan(value T, template ...string) *ValidatorNullFloat[T]

Validate if a nullable numeric value is less than another. This function internally uses the golang `<` operator. The validation only passes if the value is not null and less than the provided value. For example:

quantity := null.Val[float32]{}
quantity.Set(2.0)
Is(v.NullFloat32(quantity).LessThan(3.0))

func (*ValidatorNullFloat[T]) NaN

func (validator *ValidatorNullFloat[T]) NaN(template ...string) *ValidatorNullFloat[T]

Validate if a nullable numeric value is NaN (Not a Number). The validation only passes if the value is not null and is NaN.

For example:

quantity := null.Val[float32]{}
quantity.Set(float32(math.NaN()))
Is(v.NullFloat32(quantity).NaN())

func (*ValidatorNullFloat[T]) Negative

func (validator *ValidatorNullFloat[T]) Negative(template ...string) *ValidatorNullFloat[T]

Validate if a nullable numeric value is negative (less than zero). The validation only passes if the value is not null and less than zero.

For example:

quantity := null.Val[float32]{}
quantity.Set(-5.5)
Is(v.NullFloat32(quantity).Negative())

func (*ValidatorNullFloat[T]) Nil

func (validator *ValidatorNullFloat[T]) Nil(template ...string) *ValidatorNullFloat[T]

Validate if a nullable numeric value is null. The validation only passes if the value is null.

For example:

nullQuantity := null.Val[float32]{}
Is(v.NullFloat32(nullQuantity).Nil())

func (*ValidatorNullFloat[T]) Not

func (validator *ValidatorNullFloat[T]) Not() *ValidatorNullFloat[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with the Zero() function
quantity := null.Val[float32]{}
quantity.Set(0.0)
Is(v.NullFloat32(quantity).Not().Zero()).Valid()

func (*ValidatorNullFloat[T]) Or

func (validator *ValidatorNullFloat[T]) Or() *ValidatorNullFloat[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the input is Zero.
input := null.Val[float32]{}
input.Set(0.0)
isValid := v.Is(v.NullFloat32(input).GreaterThan(5.0).Or().Zero()).Valid()

func (*ValidatorNullFloat[T]) Passing

func (validator *ValidatorNullFloat[T]) Passing(function func(v null.Val[T]) bool, template ...string) *ValidatorNullFloat[T]

Validate if a nullable numeric value passes a custom function. The validation only passes if the value is not null and the custom function returns true. For example:

quantity := null.Val[float32]{}
quantity.Set(2.0)
Is(v.NullFloat32(quantity).Passing((v float32) bool {
	return v == getAllowedQuantity()
})

func (*ValidatorNullFloat[T]) Positive

func (validator *ValidatorNullFloat[T]) Positive(template ...string) *ValidatorNullFloat[T]

Validate if a nullable numeric value is positive (greater than zero). The validation only passes if the value is not null and greater than zero.

For example:

quantity := null.Val[float32]{}
quantity.Set(5.5)
Is(v.NullFloat32(quantity).Positive())

func (*ValidatorNullFloat[T]) Zero

func (validator *ValidatorNullFloat[T]) Zero(template ...string) *ValidatorNullFloat[T]

Validate if a nullable numeric value is zero. The validation only passes if the value is not null and equal to zero.

For example:

quantity := null.Val[float32]{}
quantity.Set(0.0)
Is(v.NullFloat32(quantity).Zero())

func (*ValidatorNullFloat[T]) ZeroOrNil

func (validator *ValidatorNullFloat[T]) ZeroOrNil(template ...string) *ValidatorNullFloat[T]

Validate if a nullable numeric value is zero or null. The validation passes if the value is null or equal to zero.

For example:

quantity := null.Val[float32]{}
quantity.Set(0.0)
Is(v.NullFloat32(quantity).ZeroOrNil())

nullQuantity := null.Val[float32]{}
Is(v.NullFloat32(nullQuantity).ZeroOrNil())

type ValidatorNullInt

type ValidatorNullInt[T ~int | ~int8 | ~int16 | ~int32 | ~int64] struct {
	// contains filtered or unexported fields
}

The ValidatorNullInt provides functions for setting validation rules for nullable int value types from the Opt library (null.Val[T]), or a custom type based on a int, int8, int16, int32, or int64. These validators properly handle the nullable nature of null.Val[T] types, only validating when a value is not null.

func NullInt

func NullInt[T ~int | ~int8 | ~int16 | ~int32 | ~int64](value null.Val[T], nameAndTitle ...string) *ValidatorNullInt[T]

Receives a nullable int value (null.Val[T]) to validate.

The value can also be a custom int type such as type Age int, wrapped in null.Val. The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func NullInt8

func NullInt8[T ~int8](value null.Val[T], nameAndTitle ...string) *ValidatorNullInt[T]

Receives a nullable int8 value (null.Val[T]) to validate.

The value can also be a custom int8 type such as type Age int8, wrapped in null.Val. The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func NullInt16

func NullInt16[T ~int16](value null.Val[T], nameAndTitle ...string) *ValidatorNullInt[T]

Receives a nullable int16 value (null.Val[T]) to validate.

The value can also be a custom int16 type such as type Age int16, wrapped in null.Val. The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func NullInt32

func NullInt32[T ~int32](value null.Val[T], nameAndTitle ...string) *ValidatorNullInt[T]

Receives a nullable int32 value (null.Val[T]) to validate.

The value can also be a custom int32 type such as type Age int32, wrapped in null.Val. The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func NullInt64

func NullInt64[T ~int64](value null.Val[T], nameAndTitle ...string) *ValidatorNullInt[T]

Receives a nullable int64 value (null.Val[T]) to validate.

The value can also be a custom int64 type such as type Age int64, wrapped in null.Val. The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func (*ValidatorNullInt[T]) Between

func (validator *ValidatorNullInt[T]) Between(min T, max T, template ...string) *ValidatorNullInt[T]

Validate if a nullable number is within a range (inclusive). The validation only passes if the value is not null and within the specified range. For example:

quantity := null.Val[int]{}
quantity.Set(3)
Is(v.NullInt(quantity).Between(2,6))

func (*ValidatorNullInt[T]) Context

func (validator *ValidatorNullInt[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorNullInt[T]) EqualTo

func (validator *ValidatorNullInt[T]) EqualTo(value T, template ...string) *ValidatorNullInt[T]

Validate if a nullable numeric value is equal to another. This function internally uses the golang `==` operator. The validation only passes if the value is not null and equal to the provided value. For example:

quantity := null.Val[int]{}
quantity.Set(2)
Is(v.NullInt(quantity).EqualTo(2))

func (*ValidatorNullInt[T]) GreaterOrEqualTo

func (validator *ValidatorNullInt[T]) GreaterOrEqualTo(value T, template ...string) *ValidatorNullInt[T]

Validate if a nullable numeric value is greater than or equal to another. This function internally uses the golang `>=` operator. The validation only passes if the value is not null and greater than or equal to the provided value. For example:

quantity := null.Val[int]{}
quantity.Set(3)
Is(v.NullInt(quantity).GreaterOrEqualTo(3))

func (*ValidatorNullInt[T]) GreaterThan

func (validator *ValidatorNullInt[T]) GreaterThan(value T, template ...string) *ValidatorNullInt[T]

Validate if a nullable numeric value is greater than another. This function internally uses the golang `>` operator. The validation only passes if the value is not null and greater than the provided value. For example:

quantity := null.Val[int]{}
quantity.Set(3)
Is(v.NullInt(quantity).GreaterThan(2))

func (*ValidatorNullInt[T]) InSlice

func (validator *ValidatorNullInt[T]) InSlice(slice []T, template ...string) *ValidatorNullInt[T]

Validate if a nullable number is present in a numeric slice. The validation only passes if the value is not null and found in the provided slice. For example:

quantity := null.Val[int]{}
quantity.Set(3)
validQuantities := []int{1,3,5}
Is(v.NullInt(quantity).InSlice(validQuantities))

func (*ValidatorNullInt[T]) LessOrEqualTo

func (validator *ValidatorNullInt[T]) LessOrEqualTo(value T, template ...string) *ValidatorNullInt[T]

Validate if a nullable numeric value is less than or equal to another. This function internally uses the golang `<=` operator. The validation only passes if the value is not null and less than or equal to the provided value. For example:

quantity := null.Val[int]{}
quantity.Set(2)
Is(v.NullInt(quantity).LessOrEqualTo(2))

func (*ValidatorNullInt[T]) LessThan

func (validator *ValidatorNullInt[T]) LessThan(value T, template ...string) *ValidatorNullInt[T]

Validate if a nullable numeric value is less than another. This function internally uses the golang `<` operator. The validation only passes if the value is not null and less than the provided value. For example:

quantity := null.Val[int]{}
quantity.Set(2)
Is(v.NullInt(quantity).LessThan(3))

func (*ValidatorNullInt[T]) Negative

func (validator *ValidatorNullInt[T]) Negative(template ...string) *ValidatorNullInt[T]

Validate if a nullable numeric value is negative (less than zero). The validation only passes if the value is not null and less than zero.

For example:

quantity := null.Val[int]{}
quantity.Set(-5)
Is(v.NullInt(quantity).Negative())

func (*ValidatorNullInt[T]) Nil

func (validator *ValidatorNullInt[T]) Nil(template ...string) *ValidatorNullInt[T]

Validate if a nullable numeric value is null. The validation only passes if the value is null.

For example:

nullQuantity := null.Val[int]{}
Is(v.NullInt(nullQuantity).Nil())

func (*ValidatorNullInt[T]) Not

func (validator *ValidatorNullInt[T]) Not() *ValidatorNullInt[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with the Zero() function
quantity := null.Val[int]{}
quantity.Set(0)
Is(v.NullInt(quantity).Not().Zero()).Valid()

func (*ValidatorNullInt[T]) Or

func (validator *ValidatorNullInt[T]) Or() *ValidatorNullInt[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the input is Zero.
input := null.Val[int]{}
input.Set(0)
isValid := v.Is(v.NullInt(input).GreaterThan(5).Or().Zero()).Valid()

func (*ValidatorNullInt[T]) Passing

func (validator *ValidatorNullInt[T]) Passing(function func(v null.Val[T]) bool, template ...string) *ValidatorNullInt[T]

Validate if a nullable numeric value passes a custom function. The validation only passes if the value is not null and the custom function returns true. For example:

quantity := null.Val[int]{}
quantity.Set(2)
Is(v.NullInt(quantity).Passing((v int) bool {
	return v == getAllowedQuantity()
})

func (*ValidatorNullInt[T]) Positive

func (validator *ValidatorNullInt[T]) Positive(template ...string) *ValidatorNullInt[T]

Validate if a nullable numeric value is positive (greater than zero). The validation only passes if the value is not null and greater than zero.

For example:

quantity := null.Val[int]{}
quantity.Set(5)
Is(v.NullInt(quantity).Positive())

func (*ValidatorNullInt[T]) Zero

func (validator *ValidatorNullInt[T]) Zero(template ...string) *ValidatorNullInt[T]

Validate if a nullable numeric value is zero. The validation only passes if the value is not null and equal to zero.

For example:

quantity := null.Val[int]{}
quantity.Set(0)
Is(v.NullInt(quantity).Zero())

func (*ValidatorNullInt[T]) ZeroOrNil

func (validator *ValidatorNullInt[T]) ZeroOrNil(template ...string) *ValidatorNullInt[T]

Validate if a nullable numeric value is zero or null. The validation passes if the value is null or equal to zero.

For example:

quantity := null.Val[int]{}
quantity.Set(0)
Is(v.NullInt(quantity).ZeroOrNil())

nullQuantity := null.Val[int]{}
Is(v.NullInt(nullQuantity).ZeroOrNil())

type ValidatorNullNumber

type ValidatorNullNumber[T TypeNumber] struct {
	// contains filtered or unexported fields
}

The ValidatorNullNumber provides functions for setting validation rules for nullable numeric value types from the Opt library (null.Val[T]), or a custom type based on a TypeNumber. These validators properly handle the nullable nature of null.Val[T] types, only validating when a value is not null.

func NullNumber

func NullNumber[T TypeNumber](value null.Val[T], nameAndTitle ...string) *ValidatorNullNumber[T]

Receives a nullable numeric value (null.Val[T]) to validate.

The value can be any golang numeric type (int64, int32, float32, uint, etc.) or a custom numeric type such as `type Level int32;`, wrapped in null.Val. The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func (*ValidatorNullNumber[T]) Between

func (validator *ValidatorNullNumber[T]) Between(min T, max T, template ...string) *ValidatorNullNumber[T]

Validate if a nullable number is within a range (inclusive). The validation only passes if the value is not null and within the specified range. For example:

quantity := null.Val[int]{}
quantity.Set(3)
Is(v.NullNumber(quantity).Between(2,6))

func (*ValidatorNullNumber[T]) Context

func (validator *ValidatorNullNumber[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorNullNumber[T]) EqualTo

func (validator *ValidatorNullNumber[T]) EqualTo(value T, template ...string) *ValidatorNullNumber[T]

Validate if a nullable numeric value is equal to another. This function internally uses the golang `==` operator. The validation only passes if the value is not null and equal to the provided value. For example:

quantity := null.Val[int]{}
quantity.Set(2)
Is(v.NullNumber(quantity).EqualTo(2))

func (*ValidatorNullNumber[T]) GreaterOrEqualTo

func (validator *ValidatorNullNumber[T]) GreaterOrEqualTo(value T, template ...string) *ValidatorNullNumber[T]

Validate if a nullable numeric value is greater than or equal to another. This function internally uses the golang `>=` operator. The validation only passes if the value is not null and greater than or equal to the provided value. For example:

quantity := null.Val[int]{}
quantity.Set(3)
Is(v.NullNumber(quantity).GreaterOrEqualTo(3))

func (*ValidatorNullNumber[T]) GreaterThan

func (validator *ValidatorNullNumber[T]) GreaterThan(value T, template ...string) *ValidatorNullNumber[T]

Validate if a nullable numeric value is greater than another. This function internally uses the golang `>` operator. The validation only passes if the value is not null and greater than the provided value. For example:

quantity := null.Val[int]{}
quantity.Set(3)
Is(v.NullNumber(quantity).GreaterThan(2))

func (*ValidatorNullNumber[T]) InSlice

func (validator *ValidatorNullNumber[T]) InSlice(slice []T, template ...string) *ValidatorNullNumber[T]

Validate if a nullable number is present in a numeric slice. The validation only passes if the value is not null and found in the provided slice. For example:

quantity := null.Val[int]{}
quantity.Set(3)
validQuantities := []int{1,3,5}
Is(v.NullNumber(quantity).InSlice(validQuantities))

func (*ValidatorNullNumber[T]) LessOrEqualTo

func (validator *ValidatorNullNumber[T]) LessOrEqualTo(value T, template ...string) *ValidatorNullNumber[T]

Validate if a nullable numeric value is less than or equal to another. This function internally uses the golang `<=` operator. The validation only passes if the value is not null and less than or equal to the provided value. For example:

quantity := null.Val[int]{}
quantity.Set(2)
Is(v.NullNumber(quantity).LessOrEqualTo(2))

func (*ValidatorNullNumber[T]) LessThan

func (validator *ValidatorNullNumber[T]) LessThan(value T, template ...string) *ValidatorNullNumber[T]

Validate if a nullable numeric value is less than another. This function internally uses the golang `<` operator. The validation only passes if the value is not null and less than the provided value. For example:

quantity := null.Val[int]{}
quantity.Set(2)
Is(v.NullNumber(quantity).LessThan(3))

func (*ValidatorNullNumber[T]) Nil

func (validator *ValidatorNullNumber[T]) Nil(template ...string) *ValidatorNullNumber[T]

Validate if a nullable numeric value is null. The validation only passes if the value is null.

For example:

nullQuantity := null.Val[int]{}
Is(v.NullNumber(nullQuantity).Nil())

func (*ValidatorNullNumber[T]) Not

func (validator *ValidatorNullNumber[T]) Not() *ValidatorNullNumber[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with the Zero() function
quantity := null.Val[int]{}
quantity.Set(0)
Is(v.NullNumber(quantity).Not().Zero()).Valid()

func (*ValidatorNullNumber[T]) Or

func (validator *ValidatorNullNumber[T]) Or() *ValidatorNullNumber[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the input is Zero.
input := null.Val[int]{}
input.Set(0)
isValid := v.Is(v.NullNumber(input).GreaterThan(5).Or().Zero()).Valid()

func (*ValidatorNullNumber[T]) Passing

func (validator *ValidatorNullNumber[T]) Passing(function func(v null.Val[T]) bool, template ...string) *ValidatorNullNumber[T]

Validate if a nullable numeric value passes a custom function. The validation only passes if the value is not null and the custom function returns true. For example:

quantity := null.Val[int]{}
quantity.Set(2)
Is(v.NullNumber(quantity).Passing((v int) bool {
	return v == getAllowedQuantity()
})

func (*ValidatorNullNumber[T]) Zero

func (validator *ValidatorNullNumber[T]) Zero(template ...string) *ValidatorNullNumber[T]

Validate if a nullable numeric value is zero. The validation only passes if the value is not null and equal to zero.

For example:

quantity := null.Val[int]{}
quantity.Set(0)
Is(v.NullNumber(quantity).Zero())

func (*ValidatorNullNumber[T]) ZeroOrNil

func (validator *ValidatorNullNumber[T]) ZeroOrNil(template ...string) *ValidatorNullNumber[T]

Validate if a nullable numeric value is zero or null. The validation passes if the value is null or equal to zero.

For example:

quantity := null.Val[int]{}
quantity.Set(0)
Is(v.NullNumber(quantity).ZeroOrNil())

nullQuantity := null.Val[int]{}
Is(v.NullNumber(nullQuantity).ZeroOrNil())

type ValidatorNullString

type ValidatorNullString[T ~string] struct {
	// contains filtered or unexported fields
}

The ValidatorNullString provides functions for setting validation rules for nullable string value types from the Opt library (null.Val[T]), or a custom type based on a string. These validators properly handle the nullable nature of null.Val[T] types, only validating when a value is not null.

func NullString

func NullString[T ~string](value null.Val[T], nameAndTitle ...string) *ValidatorNullString[T]

Receives a nullable string value (null.Val[T]) to validate.

The value can also be a custom string type such as type Status string, wrapped in null.Val. The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func (*ValidatorNullString[T]) Between

func (validator *ValidatorNullString[T]) Between(min T, max T, template ...string) *ValidatorNullString[T]

Validate if the value of a nullable string is within a range (inclusive). The validation only passes if the value is not null and within the specified range. For example:

slug := null.Val[string]{}
slug.Set("ab")
Is(v.NullString(slug).Between("ab", "ac"))

func (*ValidatorNullString[T]) Blank

func (validator *ValidatorNullString[T]) Blank(template ...string) *ValidatorNullString[T]

Validate if a nullable string value is blank. Blank will be true if the length of the string is zero or if the string only has spaces. The validation only passes if the value is not null and blank. For example:

status := null.Val[string]{}
status.Set("")
Is(v.NullString(status).Blank()) // Will be true

status2 := null.Val[string]{}
status2.Set(" ")
Is(v.NullString(status2).Blank()) // Will be true

func (*ValidatorNullString[T]) Context

func (validator *ValidatorNullString[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorNullString[T]) Empty

func (validator *ValidatorNullString[T]) Empty(template ...string) *ValidatorNullString[T]

Validate if a nullable string value is empty. Return false if the length of the string is greater than zero, even if the string has only spaces. The validation only passes if the value is not null and empty.

For checking if the string has only spaces, use the function `Blank()` instead. For example:

status := null.Val[string]{}
status.Set("")
Is(v.NullString(status).Empty()) // Will be true

func (*ValidatorNullString[T]) EmptyOrNil

func (validator *ValidatorNullString[T]) EmptyOrNil(template ...string) *ValidatorNullString[T]

Validate if a nullable string value is empty or null. The validation passes if the value is null or equal to an empty string.

For example:

status := null.Val[string]{}
status.Set("")
Is(v.NullString(status).EmptyOrNil())

nullStatus := null.Val[string]{}
Is(v.NullString(nullStatus).EmptyOrNil())

func (*ValidatorNullString[T]) EqualTo

func (validator *ValidatorNullString[T]) EqualTo(value T, template ...string) *ValidatorNullString[T]

Validate if a nullable string value is equal to another. This function internally uses the golang `==` operator. The validation only passes if the value is not null and equal to the provided value. For example:

status := null.Val[string]{}
status.Set("running")
Is(v.NullString(status).EqualTo("running"))

func (*ValidatorNullString[T]) GreaterOrEqualTo

func (validator *ValidatorNullString[T]) GreaterOrEqualTo(value T, template ...string) *ValidatorNullString[T]

Validate if a nullable string value is greater than or equal to another. This function internally uses the golang `>=` operator. The validation only passes if the value is not null and greater than or equal to the provided value. For example:

section := null.Val[string]{}
section.Set("bc")
Is(v.NullString(section).GreaterOrEqualTo("bc"))

func (*ValidatorNullString[T]) GreaterThan

func (validator *ValidatorNullString[T]) GreaterThan(value T, template ...string) *ValidatorNullString[T]

Validate if a nullable string value is greater than another. This function internally uses the golang `>` operator. The validation only passes if the value is not null and greater than the provided value. For example:

section := null.Val[string]{}
section.Set("bb")
Is(v.NullString(section).GreaterThan("ba"))

func (*ValidatorNullString[T]) InSlice

func (validator *ValidatorNullString[T]) InSlice(slice []T, template ...string) *ValidatorNullString[T]

Validate if a nullable string is present in a string slice. The validation only passes if the value is not null and found in the provided slice. For example:

status := null.Val[string]{}
status.Set("idle")
validStatus := []string{"idle", "paused", "stopped"}
Is(v.NullString(status).InSlice(validStatus))

func (*ValidatorNullString[T]) LessOrEqualTo

func (validator *ValidatorNullString[T]) LessOrEqualTo(value T, template ...string) *ValidatorNullString[T]

Validate if a nullable string value is less than or equal to another. This function internally uses the golang `<=` operator. The validation only passes if the value is not null and less than or equal to the provided value. For example:

section := null.Val[string]{}
section.Set("bc")
Is(v.NullString(section).LessOrEqualTo("bc"))

func (*ValidatorNullString[T]) LessThan

func (validator *ValidatorNullString[T]) LessThan(value T, template ...string) *ValidatorNullString[T]

Validate if a nullable string value is less than another. This function internally uses the golang `<` operator. The validation only passes if the value is not null and less than the provided value. For example:

section := null.Val[string]{}
section.Set("bb")
Is(v.NullString(section).LessThan("bc"))

func (*ValidatorNullString[T]) MatchingTo

func (validator *ValidatorNullString[T]) MatchingTo(regex *regexp.Regexp, template ...string) *ValidatorNullString[T]

Validate if a nullable string matches a regular expression. The validation only passes if the value is not null and matches the provided regex. For example:

status := null.Val[string]{}
status.Set("pre-approved")
regex, _ := regexp.Compile("pre-.+")
Is(v.NullString(status).MatchingTo(regex))

func (*ValidatorNullString[T]) MaxBytes

func (validator *ValidatorNullString[T]) MaxBytes(length int, template ...string) *ValidatorNullString[T]

Validate the maximum length (in bytes) of a nullable string. The validation only passes if the value is not null and its byte length is less than or equal to the provided length. For example:

slug := null.Val[string]{}
slug.Set("myname")
Is(v.NullString(slug).MaxBytes(6))

For character count, use `MaxLength` instead.

func (*ValidatorNullString[T]) MaxLength

func (validator *ValidatorNullString[T]) MaxLength(length int, template ...string) *ValidatorNullString[T]

Validate the maximum length (in runes/characters) of a nullable string. The validation only passes if the value is not null and its rune length is less than or equal to the provided length. For example:

word := null.Val[string]{}
word.Set("虎視眈々") // 4 runes, len(word) = 12 bytes
Is(v.NullString(word).MaxLength(4))

func (*ValidatorNullString[T]) MinBytes

func (validator *ValidatorNullString[T]) MinBytes(length int, template ...string) *ValidatorNullString[T]

Validate the minimum length (in bytes) of a nullable string. The validation only passes if the value is not null and its byte length is greater than or equal to the provided length. For example:

slug := null.Val[string]{}
slug.Set("myname")
Is(v.NullString(slug).MinBytes(6))

For character count, use `MinLength` instead.

func (*ValidatorNullString[T]) MinLength

func (validator *ValidatorNullString[T]) MinLength(length int, template ...string) *ValidatorNullString[T]

Validate the minimum length (in runes/characters) of a nullable string. The validation only passes if the value is not null and its rune length is greater than or equal to the provided length. For example:

word := null.Val[string]{}
word.Set("虎視眈々") // 4 runes, len(word) = 12 bytes
Is(v.NullString(word).MinLength(4))

func (*ValidatorNullString[T]) Nil

func (validator *ValidatorNullString[T]) Nil(template ...string) *ValidatorNullString[T]

Validate if a nullable string value is null. The validation only passes if the value is null.

For example:

nullStatus := null.Val[string]{}
Is(v.NullString(nullStatus).Nil())

func (*ValidatorNullString[T]) Not

func (validator *ValidatorNullString[T]) Not() *ValidatorNullString[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with the Empty() function
status := null.Val[string]{}
status.Set("")
Is(v.NullString(status).Not().Empty()).Valid()

func (*ValidatorNullString[T]) OfByteLength

func (validator *ValidatorNullString[T]) OfByteLength(length int, template ...string) *ValidatorNullString[T]

Validate the length (in bytes) of a nullable string. The validation only passes if the value is not null and its byte length equals the provided length. For example:

slug := null.Val[string]{}
slug.Set("myname")
Is(v.NullString(slug).OfByteLength(6))

For character count, use `OfLength` instead.

func (*ValidatorNullString[T]) OfByteLengthBetween

func (validator *ValidatorNullString[T]) OfByteLengthBetween(min int, max int, template ...string) *ValidatorNullString[T]

Validate if the length (in bytes) of a nullable string is within a range (inclusive). The validation only passes if the value is not null and its byte length is within the specified range. For example:

slug := null.Val[string]{}
slug.Set("myname")
Is(v.NullString(slug).OfByteLengthBetween(2, 6))

For character count, use `OfLengthBetween` instead.

func (*ValidatorNullString[T]) OfLength

func (validator *ValidatorNullString[T]) OfLength(length int, template ...string) *ValidatorNullString[T]

Validate the length (in runes/characters) of a nullable string. The validation only passes if the value is not null and its rune length equals the provided length. For example:

word := null.Val[string]{}
word.Set("虎視眈々") // 4 runes, len(word) = 12 bytes
Is(v.NullString(word).OfLength(4))

func (*ValidatorNullString[T]) OfLengthBetween

func (validator *ValidatorNullString[T]) OfLengthBetween(min int, max int, template ...string) *ValidatorNullString[T]

Validate if the length (in runes/characters) of a nullable string is within a range (inclusive). The validation only passes if the value is not null and its rune length is within the specified range. For example:

word := null.Val[string]{}
word.Set("虎視眈々") // 4 runes, len(word) = 12 bytes
Is(v.NullString(word).OfLengthBetween(2, 4))

func (*ValidatorNullString[T]) Or

func (validator *ValidatorNullString[T]) Or() *ValidatorNullString[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the string is equal to "test".
input := null.Val[string]{}
input.Set("test")
isValid := v.Is(v.NullString(input).MinLength(5).Or().EqualTo("test")).Valid()

func (*ValidatorNullString[T]) Passing

func (validator *ValidatorNullString[T]) Passing(function func(v null.Val[T]) bool, template ...string) *ValidatorNullString[T]

Validate if a nullable string value passes a custom function. The validation only passes if the value is not null and the custom function returns true. For example:

status := null.Val[string]{}
status.Set("")
Is(v.NullString(status).Passing((v string) bool {
	return v == getNewStatus()
})

type ValidatorNullTime

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

The ValidatorNullTime provides functions for setting validation rules for nullable time.Time value types from the Opt library (null.Val[time.Time]). These validators properly handle the nullable nature of null.Val[T] types, only validating when a value is not null.

func NullTime

func NullTime(value null.Val[time.Time], nameAndTitle ...string) *ValidatorNullTime

Receives a nullable time.Time value (null.Val[time.Time]) to validate.

The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `start_time` will be humanized as `Start Time`

func (*ValidatorNullTime) After

func (validator *ValidatorNullTime) After(value time.Time, template ...string) *ValidatorNullTime

Validate if a nullable time value is after a specified time. The validation only passes if the value is not null and after the provided value.

For example:

startTime := null.Val[time.Time]{}
startTime.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
endTime := time.Date(2023, 1, 1, 1, 0, 0, 0, time.UTC)
Is(v.NullTime(endTime).After(startTime)).Valid()

func (*ValidatorNullTime) AfterOrEqualTo

func (validator *ValidatorNullTime) AfterOrEqualTo(value time.Time, template ...string) *ValidatorNullTime

Validate if a nullable time value is either after or equal to a specified time. The validation only passes if the value is not null and after or equal to the provided value.

For example:

timeA := null.Val[time.Time]{}
timeA.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
timeB := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
Is(v.NullTime(timeA).AfterOrEqualTo(timeB)).Valid()

func (*ValidatorNullTime) Before

func (validator *ValidatorNullTime) Before(value time.Time, template ...string) *ValidatorNullTime

Validate if a nullable time value is before a specified time. The validation only passes if the value is not null and before the provided value.

For example:

startTime := null.Val[time.Time]{}
startTime.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
endTime := time.Date(2023, 1, 1, 1, 0, 0, 0, time.UTC)
Is(v.NullTime(startTime).Before(endTime)).Valid()

func (*ValidatorNullTime) BeforeOrEqualTo

func (validator *ValidatorNullTime) BeforeOrEqualTo(value time.Time, template ...string) *ValidatorNullTime

Validate if a nullable time value is either before or equal to a specified time. The validation only passes if the value is not null and before or equal to the provided value.

For example:

timeA := null.Val[time.Time]{}
timeA.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
timeB := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
Is(v.NullTime(timeA).BeforeOrEqualTo(timeB)).Valid()

func (*ValidatorNullTime) Between

func (validator *ValidatorNullTime) Between(min time.Time, max time.Time, template ...string) *ValidatorNullTime

Validate if a nullable time value falls within a given time range, inclusive. The validation only passes if the value is not null and within the specified range.

For example:

minTime := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
maxTime := time.Date(2023, 1, 1, 12, 0, 0, 0, time.UTC)
checkTime := null.Val[time.Time]{}
checkTime.Set(time.Date(2023, 1, 1, 6, 0, 0, 0, time.UTC))
Is(v.NullTime(checkTime).Between(minTime, maxTime)).Valid()

func (*ValidatorNullTime) Context

func (validator *ValidatorNullTime) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorNullTime) EqualTo

func (validator *ValidatorNullTime) EqualTo(value time.Time, template ...string) *ValidatorNullTime

Validate if a nullable time value is equal to another. The validation only passes if the value is not null and equal to the provided value.

For example:

timeA := null.Val[time.Time]{}
timeA.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
timeB := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
Is(v.NullTime(timeA).EqualTo(timeB)).Valid()

func (*ValidatorNullTime) InSlice

func (validator *ValidatorNullTime) InSlice(slice []time.Time, template ...string) *ValidatorNullTime

Validate if a nullable time value is found within a provided slice of time values. The validation only passes if the value is not null and found in the provided slice.

For example:

timeA := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
timeB := time.Date(2023, 1, 1, 1, 0, 0, 0, time.UTC)
timeSlice := []time.Time{timeA, timeB}
checkTime := null.Val[time.Time]{}
checkTime.Set(time.Date(2023, 1, 1, 1, 0, 0, 0, time.UTC))
Is(v.NullTime(checkTime).InSlice(timeSlice)).Valid()

func (*ValidatorNullTime) Nil

func (validator *ValidatorNullTime) Nil(template ...string) *ValidatorNullTime

Validate if a nullable time value is null. The validation only passes if the value is null.

For example:

nullTime := null.Val[time.Time]{}
Is(v.NullTime(nullTime).Nil())

func (*ValidatorNullTime) Not

func (validator *ValidatorNullTime) Not() *ValidatorNullTime

Invert the logical value associated with the next validator function. For example:

// It will return false because `Not()` inverts the boolean value associated with the Zero() function
startTime := null.Val[time.Time]{}
startTime.Set(time.Now())
Is(v.NullTime(startTime).Not().Zero()).Valid()

func (*ValidatorNullTime) Or

func (validator *ValidatorNullTime) Or() *ValidatorNullTime

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the time is before or equal to time.Now().
t := null.Val[time.Time]{}
t.Set(time.Now())
isValid := v.Is(v.NullTime(t).Zero().Or().BeforeOrEqualTo(time.Now())).Valid()

func (*ValidatorNullTime) Passing

func (validator *ValidatorNullTime) Passing(function func(v0 null.Val[time.Time]) bool, template ...string) *ValidatorNullTime

Validate if a nullable time value passes a custom function. The validation only passes if the value is not null and the custom function returns true.

For example:

checkTime := null.Val[time.Time]{}
checkTime.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
Is(v.NullTime(checkTime).Passing(func(t time.Time) bool {
    return t.Year() == 2023
})).Valid()

func (*ValidatorNullTime) Zero

func (validator *ValidatorNullTime) Zero(template ...string) *ValidatorNullTime

Validate if a nullable time value is a zero time. The validation only passes if the value is not null and is a zero time.

For example:

zeroTime := null.Val[time.Time]{}
zeroTime.Set(time.Time{})
Is(v.NullTime(zeroTime).Zero()).Valid()

func (*ValidatorNullTime) ZeroOrNil

func (validator *ValidatorNullTime) ZeroOrNil(template ...string) *ValidatorNullTime

Validate if a nullable time value is zero or null. The validation only passes if the value is null or (set and not null and equal to zero).

For example:

zeroTime := null.Val[time.Time]{}
zeroTime.Set(time.Time{})
Is(v.NullTime(zeroTime).ZeroOrNil())

nullTime := null.Val[time.Time]{}
Is(v.NullTime(nullTime).ZeroOrNil())

type ValidatorNullTyped

type ValidatorNullTyped[T any] struct {
	// contains filtered or unexported fields
}

The ValidatorNullTyped provides functions for setting validation rules for nullable value types from the Opt library (null.Val[T]), or a custom type. T can be any Go type (pointer, struct, slice, map, etc.). These validators properly handle the nullable nature of null.Val[T] types, only validating when a value is not null.

func NullTyped

func NullTyped[T any](value null.Val[T], nameAndTitle ...string) *ValidatorNullTyped[T]

Receives a nullable value (null.Val[T]) to validate.

The value can be any Go type (pointer, struct, slice, map, etc.), wrapped in null.Val. The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A value_%N pattern is used as a name in the error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name phone_number will be humanized as Phone Number.

Example:

user := null.Val[User]{}
user.Set(User{Name: "John"})
v.Is(v.NullTyped(user).Not().Nil())

func (*ValidatorNullTyped[T]) Context

func (validator *ValidatorNullTyped[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorNullTyped[T]) EqualTo

func (validator *ValidatorNullTyped[T]) EqualTo(value T, template ...string) *ValidatorNullTyped[T]

Validate if a nullable value is equal to another. This function uses reflection to compare values, which works for all types including incomparable types. The validation only passes if the value is not null and equal to the provided value. For example:

status := null.Val[string]{}
status.Set("running")
Is(v.NullTyped(status).EqualTo("running"))

func (*ValidatorNullTyped[T]) Nil

func (validator *ValidatorNullTyped[T]) Nil(template ...string) *ValidatorNullTyped[T]

Validate if a nullable value is nil. The validation passes if: - The null.Val itself is null (not set), OR - The value inside is nil (for nil-able types like pointers, slices, maps, etc.)

For example:

nullVal := null.Val[*string]{}
v.Is(v.NullTyped(nullVal).Nil())

var s *string
val := null.Val[*string]{}
val.Set(s)
v.Is(v.NullTyped(val).Nil())

func (*ValidatorNullTyped[T]) Not

func (validator *ValidatorNullTyped[T]) Not() *ValidatorNullTyped[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with EqualTo()
val := null.Val[string]{}
val.Set("a")
v.Is(v.NullTyped(val).Not().EqualTo("a")).Valid()

func (*ValidatorNullTyped[T]) Or

func (validator *ValidatorNullTyped[T]) Or() *ValidatorNullTyped[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the value is equal to "test".
input := null.Val[string]{}
input.Set("test")
isValid := v.Is(v.NullTyped(input).Passing(func(s string) bool { return len(s) >= 5 }).Or().EqualTo("test")).Valid()

func (*ValidatorNullTyped[T]) Passing

func (validator *ValidatorNullTyped[T]) Passing(function func(v null.Val[T]) bool, template ...string) *ValidatorNullTyped[T]

Validate if a nullable value passes a custom function. The function receives a typed T value, enabling compile-time type safety. The validation only passes if the value is not null and the function returns true.

For example:

type Status string
status := null.Val[Status]{}
status.Set(Status("running"))
isValid := v.Is(
  v.NullTyped(status).Passing(func(s Status) bool {
    return s == "running" || s == "paused"
  }),
).Valid()

type ValidatorNullUint

type ValidatorNullUint[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64] struct {
	// contains filtered or unexported fields
}

The ValidatorNullUint provides functions for setting validation rules for nullable uint value types from the Opt library (null.Val[T]), or a custom type based on a uint, uint8, uint16, uint32, or uint64. These validators properly handle the nullable nature of null.Val[T] types, only validating when a value is not null.

func NullByte

func NullByte[T ~byte](value null.Val[T], nameAndTitle ...string) *ValidatorNullUint[T]

Receives a nullable byte value (null.Val[T]) to validate.

The value can also be a custom byte type such as type Age byte, wrapped in null.Val. The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func NullUint

func NullUint[T ~uint](value null.Val[T], nameAndTitle ...string) *ValidatorNullUint[T]

Receives a nullable uint value (null.Val[T]) to validate.

The value can also be a custom uint type such as type Age uint, wrapped in null.Val. The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func NullUint8

func NullUint8[T ~uint8](value null.Val[T], nameAndTitle ...string) *ValidatorNullUint[T]

Receives a nullable uint8 value (null.Val[T]) to validate.

The value can also be a custom uint8 type such as type Age uint8, wrapped in null.Val. The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func NullUint16

func NullUint16[T ~uint16](value null.Val[T], nameAndTitle ...string) *ValidatorNullUint[T]

Receives a nullable uint16 value (null.Val[T]) to validate.

The value can also be a custom uint16 type such as type Age uint16, wrapped in null.Val. The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func NullUint32

func NullUint32[T ~uint32](value null.Val[T], nameAndTitle ...string) *ValidatorNullUint[T]

Receives a nullable uint32 value (null.Val[T]) to validate.

The value can also be a custom uint32 type such as type Age uint32, wrapped in null.Val. The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func NullUint64

func NullUint64[T ~uint64](value null.Val[T], nameAndTitle ...string) *ValidatorNullUint[T]

Receives a nullable uint64 value (null.Val[T]) to validate.

The value can also be a custom uint64 type such as type Age uint64, wrapped in null.Val. The validator will only perform validation checks when the value is not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func (*ValidatorNullUint[T]) Between

func (validator *ValidatorNullUint[T]) Between(min T, max T, template ...string) *ValidatorNullUint[T]

Validate if a nullable number is within a range (inclusive). The validation only passes if the value is not null and within the specified range. For example:

quantity := null.Val[uint]{}
quantity.Set(3)
Is(v.NullUint(quantity).Between(2,6))

func (*ValidatorNullUint[T]) Context

func (validator *ValidatorNullUint[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorNullUint[T]) EqualTo

func (validator *ValidatorNullUint[T]) EqualTo(value T, template ...string) *ValidatorNullUint[T]

Validate if a nullable numeric value is equal to another. This function internally uses the golang `==` operator. The validation only passes if the value is not null and equal to the provided value. For example:

quantity := null.Val[uint]{}
quantity.Set(2)
Is(v.NullUint(quantity).EqualTo(2))

func (*ValidatorNullUint[T]) GreaterOrEqualTo

func (validator *ValidatorNullUint[T]) GreaterOrEqualTo(value T, template ...string) *ValidatorNullUint[T]

Validate if a nullable numeric value is greater than or equal to another. This function internally uses the golang `>=` operator. The validation only passes if the value is not null and greater than or equal to the provided value. For example:

quantity := null.Val[uint]{}
quantity.Set(3)
Is(v.NullUint(quantity).GreaterOrEqualTo(3))

func (*ValidatorNullUint[T]) GreaterThan

func (validator *ValidatorNullUint[T]) GreaterThan(value T, template ...string) *ValidatorNullUint[T]

Validate if a nullable numeric value is greater than another. This function internally uses the golang `>` operator. The validation only passes if the value is not null and greater than the provided value. For example:

quantity := null.Val[uint]{}
quantity.Set(3)
Is(v.NullUint(quantity).GreaterThan(2))

func (*ValidatorNullUint[T]) InSlice

func (validator *ValidatorNullUint[T]) InSlice(slice []T, template ...string) *ValidatorNullUint[T]

Validate if a nullable number is present in a numeric slice. The validation only passes if the value is not null and found in the provided slice. For example:

quantity := null.Val[uint]{}
quantity.Set(3)
validQuantities := []uint{1,3,5}
Is(v.NullUint(quantity).InSlice(validQuantities))

func (*ValidatorNullUint[T]) LessOrEqualTo

func (validator *ValidatorNullUint[T]) LessOrEqualTo(value T, template ...string) *ValidatorNullUint[T]

Validate if a nullable numeric value is less than or equal to another. This function internally uses the golang `<=` operator. The validation only passes if the value is not null and less than or equal to the provided value. For example:

quantity := null.Val[uint]{}
quantity.Set(2)
Is(v.NullUint(quantity).LessOrEqualTo(2))

func (*ValidatorNullUint[T]) LessThan

func (validator *ValidatorNullUint[T]) LessThan(value T, template ...string) *ValidatorNullUint[T]

Validate if a nullable numeric value is less than another. This function internally uses the golang `<` operator. The validation only passes if the value is not null and less than the provided value. For example:

quantity := null.Val[uint]{}
quantity.Set(2)
Is(v.NullUint(quantity).LessThan(3))

func (*ValidatorNullUint[T]) Nil

func (validator *ValidatorNullUint[T]) Nil(template ...string) *ValidatorNullUint[T]

Validate if a nullable numeric value is null. The validation only passes if the value is null.

For example:

nullQuantity := null.Val[uint]{}
Is(v.NullUint(nullQuantity).Nil())

func (*ValidatorNullUint[T]) Not

func (validator *ValidatorNullUint[T]) Not() *ValidatorNullUint[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with the Zero() function
quantity := null.Val[uint]{}
quantity.Set(0)
Is(v.NullUint(quantity).Not().Zero()).Valid()

func (*ValidatorNullUint[T]) Or

func (validator *ValidatorNullUint[T]) Or() *ValidatorNullUint[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the input is Zero.
input := null.Val[uint]{}
input.Set(0)
isValid := v.Is(v.NullUint(input).GreaterThan(5).Or().Zero()).Valid()

func (*ValidatorNullUint[T]) Passing

func (validator *ValidatorNullUint[T]) Passing(function func(v null.Val[T]) bool, template ...string) *ValidatorNullUint[T]

Validate if a nullable numeric value passes a custom function. The validation only passes if the value is not null and the custom function returns true. For example:

quantity := null.Val[uint]{}
quantity.Set(2)
Is(v.NullUint(quantity).Passing((v uint) bool {
	return v == getAllowedQuantity()
})

func (*ValidatorNullUint[T]) Positive

func (validator *ValidatorNullUint[T]) Positive(template ...string) *ValidatorNullUint[T]

Validate if a nullable numeric value is positive (greater than zero). The validation only passes if the value is not null and greater than zero.

For example:

quantity := null.Val[uint]{}
quantity.Set(5)
Is(v.NullUint(quantity).Positive())

func (*ValidatorNullUint[T]) Zero

func (validator *ValidatorNullUint[T]) Zero(template ...string) *ValidatorNullUint[T]

Validate if a nullable numeric value is zero. The validation only passes if the value is not null and equal to zero.

For example:

quantity := null.Val[uint]{}
quantity.Set(0)
Is(v.NullUint(quantity).Zero())

func (*ValidatorNullUint[T]) ZeroOrNil

func (validator *ValidatorNullUint[T]) ZeroOrNil(template ...string) *ValidatorNullUint[T]

Validate if a nullable numeric value is zero or null. The validation passes if the value is null or equal to zero.

For example:

quantity := null.Val[uint]{}
quantity.Set(0)
Is(v.NullUint(quantity).ZeroOrNil())

nullQuantity := null.Val[uint]{}
Is(v.NullUint(nullQuantity).ZeroOrNil())

type ValidatorOmitAny

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

The ValidatorOmitAny provides functions for setting validation rules for optional value types from the Opt library (omit.Val[any]). These validators properly handle the optional nature of omit.Val[any] types, only validating when a value is set.

func OmitAny

func OmitAny(value omit.Val[any], nameAndTitle ...string) *ValidatorOmitAny

Receives an optional value (omit.Val[any]) to validate.

The value can be any type wrapped in omit.Val[any]. The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A value_%N pattern is used as a name in the error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name phone_number will be humanized as Phone Number.

func (*ValidatorOmitAny) Context

func (validator *ValidatorOmitAny) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitAny) EqualTo

func (validator *ValidatorOmitAny) EqualTo(value any, template ...string) *ValidatorOmitAny

Validate if an optional value is equal to another. This function uses reflection to compare values, which works for all types including incomparable types. The validation only passes if the value is set and equal to the provided value. For example:

status := omit.Val[any]{}
status.Set("running")
Is(v.OmitAny(status).EqualTo("running"))

DEPRECATED: 'any' is not safely comparable. Use the OmitTyped validator instead. This function will be removed in Valgo v1.0.0.

func (*ValidatorOmitAny) Nil

func (validator *ValidatorOmitAny) Nil(template ...string) *ValidatorOmitAny

Validate if an optional value is nil. Works for nil-able kinds: pointers, slices, maps, chans, funcs, and interfaces. For non-nil-able types, this will return false. The validation only passes if the value is set and is nil. For example:

var status *string
val := omit.Val[any]{}
val.Set(status)
Is(v.OmitAny(val).Nil())

func (*ValidatorOmitAny) Not

func (validator *ValidatorOmitAny) Not() *ValidatorOmitAny

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with the EqualTo() function
val := omit.Val[any]{}
val.Set("a")
Is(v.OmitAny(val).Not().EqualTo("a")).Valid()

func (*ValidatorOmitAny) Or

func (validator *ValidatorOmitAny) Or() *ValidatorOmitAny

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the value is equal to "test".
input := omit.Val[any]{}
input.Set("test")
isValid := v.Is(v.OmitAny(input).Passing(func(v any) bool { return v == nil }).Or().EqualTo("test")).Valid()

func (*ValidatorOmitAny) Passing

func (validator *ValidatorOmitAny) Passing(function func(v omit.Val[any]) bool, template ...string) *ValidatorOmitAny

Validate if an optional value passes a custom function. The validation only passes if the value is set and the custom function returns true. For example:

status := omit.Val[any]{}
status.Set("")
Is(v.OmitAny(status).Passing((v any) bool {
	return v == getNewStatus()
})

func (*ValidatorOmitAny) Set

func (validator *ValidatorOmitAny) Set(template ...string) *ValidatorOmitAny

Validate if an optional value is set (not unset). The validation passes if the value is set, regardless of its content.

For example:

user := omit.Val[any]{}
user.Set(User{Name: "John"})
Is(v.OmitAny(user).Set())

type ValidatorOmitBoolean

type ValidatorOmitBoolean[T ~bool] struct {
	// contains filtered or unexported fields
}

The ValidatorOmitBoolean provides functions for setting validation rules for optional boolean value types from the Opt library (omit.Val[T]), or a custom type based on a bool. These validators properly handle the optional nature of omit.Val[T] types, only validating when a value is set.

func OmitBoolean

func OmitBoolean[T ~bool](value omit.Val[T], nameAndTitle ...string) *ValidatorOmitBoolean[T]

Receives an optional boolean value (omit.Val[T]) to validate.

The value can also be a custom boolean type such as `type Active bool;`, wrapped in omit.Val. The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func (*ValidatorOmitBoolean[T]) Context

func (validator *ValidatorOmitBoolean[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitBoolean[T]) EqualTo

func (validator *ValidatorOmitBoolean[T]) EqualTo(value T, template ...string) *ValidatorOmitBoolean[T]

Validate if an optional boolean value is equal to another. The validation only passes if the value is set and equal to the provided value. For example:

activated := omit.Val[bool]{}
activated.Set(true)
Is(v.OmitBoolean(activated).EqualTo(true))

func (*ValidatorOmitBoolean[T]) False

func (validator *ValidatorOmitBoolean[T]) False(template ...string) *ValidatorOmitBoolean[T]

Validate if an optional boolean value is false. The validation only passes if the value is set and equal to false. For example:

activated := omit.Val[bool]{}
activated.Set(false)
Is(v.OmitBoolean(activated).False())

func (*ValidatorOmitBoolean[T]) InSlice

func (validator *ValidatorOmitBoolean[T]) InSlice(slice []T, template ...string) *ValidatorOmitBoolean[T]

Validate if an optional boolean value is present in a boolean slice. The validation only passes if the value is set and found in the provided slice. For example:

activated := omit.Val[bool]{}
activated.Set(false)
elements := []bool{true, false, true}
Is(v.OmitBoolean(activated).InSlice(elements))

func (*ValidatorOmitBoolean[T]) Not

func (validator *ValidatorOmitBoolean[T]) Not() *ValidatorOmitBoolean[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because `Not()` inverts the boolean value associated with the True() function
activated := omit.Val[bool]{}
activated.Set(true)
Is(v.OmitBoolean(activated).Not().True()).Valid()

func (*ValidatorOmitBoolean[T]) Or

func (validator *ValidatorOmitBoolean[T]) Or() *ValidatorOmitBoolean[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the input is equals false.
input := omit.Val[bool]{}
input.Set(true)
isValid := v.Is(v.OmitBoolean(input).False().Or().True()).Valid()

func (*ValidatorOmitBoolean[T]) Passing

func (validator *ValidatorOmitBoolean[T]) Passing(function func(v omit.Val[T]) bool, template ...string) *ValidatorOmitBoolean[T]

Validate if an optional boolean value passes a custom function. The validation only passes if the value is set and the custom function returns true. For example:

activated := omit.Val[bool]{}
activated.Set(false)
Is(v.OmitBoolean(activated).Passing((v bool) bool {
	return v == someBoolFunction()
})

func (*ValidatorOmitBoolean[T]) Set

func (validator *ValidatorOmitBoolean[T]) Set(template ...string) *ValidatorOmitBoolean[T]

Validate if an optional boolean value is set. The validation only passes if the value is set. For example:

activated := omit.Val[bool]{}
activated.Set(true)
Is(v.OmitBoolean(activated).Set())

func (*ValidatorOmitBoolean[T]) True

func (validator *ValidatorOmitBoolean[T]) True(template ...string) *ValidatorOmitBoolean[T]

Validate if an optional boolean value is true. The validation only passes if the value is set and equal to true. For example:

activated := omit.Val[bool]{}
activated.Set(true)
Is(v.OmitBoolean(activated).True())

type ValidatorOmitComparable

type ValidatorOmitComparable[T comparable] struct {
	// contains filtered or unexported fields
}

The ValidatorOmitComparable provides functions for setting validation rules for optional comparable value types from the Opt library (omit.Val[T]). T can be any Go type (pointer, struct, etc.) that is comparable. These validators properly handle the optional nature of omit.Val[T] types, only validating when a value is set.

func OmitComparable

func OmitComparable[T comparable](value omit.Val[T], nameAndTitle ...string) *ValidatorOmitComparable[T]

Receives an optional comparable value (omit.Val[T]) to validate, where T must be comparable.

The value can be any Go type (pointer, struct, etc.) that is comparable, wrapped in omit.Val. The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A value_%N pattern is used as a name in the error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name phone_number will be humanized as Phone Number.

Example:

status := omit.Val[string]{}
status.Set("running")
v.Is(v.OmitComparable(status).Not().EqualTo("stopped"))

func (*ValidatorOmitComparable[T]) Context

func (validator *ValidatorOmitComparable[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitComparable[T]) EqualTo

func (validator *ValidatorOmitComparable[T]) EqualTo(value T, template ...string) *ValidatorOmitComparable[T]

Validate if an optional value is equal to another. This function internally uses the golang `==` operator. The validation only passes if the value is set and equal to the provided value. For example:

status := omit.Val[string]{}
status.Set("running")
Is(v.OmitComparable(status).EqualTo("running"))

func (*ValidatorOmitComparable[T]) InSlice

func (validator *ValidatorOmitComparable[T]) InSlice(slice []T, template ...string) *ValidatorOmitComparable[T]

Validate if an optional value is present in a slice. The validation only passes if the value is set and found in the provided slice. For example:

status := omit.Val[string]{}
status.Set("idle")
validStatus := []string{"idle", "paused", "stopped"}
Is(v.OmitComparable(status).InSlice(validStatus))

func (*ValidatorOmitComparable[T]) Not

func (validator *ValidatorOmitComparable[T]) Not() *ValidatorOmitComparable[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because `Not()` inverts the boolean value associated with `EqualTo()`
val := omit.Val[string]{}
val.Set("a")
v.Is(v.OmitComparable(val).Not().EqualTo("a")).Valid()

func (*ValidatorOmitComparable[T]) Or

func (validator *ValidatorOmitComparable[T]) Or() *ValidatorOmitComparable[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the string is equals "running".
status := omit.Val[string]{}
status.Set("running")
isValid := v.Is(v.OmitComparable(status).EqualTo("paused").Or().EqualTo("running")).Valid()

func (*ValidatorOmitComparable[T]) Passing

func (validator *ValidatorOmitComparable[T]) Passing(function func(v omit.Val[T]) bool, template ...string) *ValidatorOmitComparable[T]

Validate if an optional value passes a custom function. The function receives a typed T value, enabling compile-time type safety. The validation only passes if the value is set and the custom function returns true.

For example:

type Status string
status := omit.Val[Status]{}
status.Set(Status("running"))
isValid := v.Is(
  v.OmitComparable(status).Passing(func(s Status) bool {
    return s == "running" || s == "paused"
  }),
).Valid()

func (*ValidatorOmitComparable[T]) Set

func (validator *ValidatorOmitComparable[T]) Set(template ...string) *ValidatorOmitComparable[T]

Validate if an optional value is set (not unset). The validation passes if the value is set, regardless of its content.

For example:

status := omit.Val[string]{}
status.Set("running")
Is(v.OmitComparable(status).Set())

type ValidatorOmitFloat

type ValidatorOmitFloat[T ~float32 | ~float64] struct {
	// contains filtered or unexported fields
}

The ValidatorOmitFloat provides functions for setting validation rules for optional float value types from the Opt library (omit.Val[T]), or a custom type based on a float32 or float64. These validators properly handle the optional nature of omit.Val[T] types, only validating when a value is set.

func OmitFloat32

func OmitFloat32[T ~float32](value omit.Val[T], nameAndTitle ...string) *ValidatorOmitFloat[T]

Receives an optional float32 value (omit.Val[T]) to validate.

The value can also be a custom float32 type such as type Price float32, wrapped in omit.Val. The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitFloat64

func OmitFloat64[T ~float64](value omit.Val[T], nameAndTitle ...string) *ValidatorOmitFloat[T]

Receives an optional float64 value (omit.Val[T]) to validate.

The value can also be a custom float64 type such as type Price float64, wrapped in omit.Val. The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func (*ValidatorOmitFloat[T]) Between

func (validator *ValidatorOmitFloat[T]) Between(min T, max T, template ...string) *ValidatorOmitFloat[T]

Validate if an optional number is within a range (inclusive). The validation only passes if the value is set and within the specified range. For example:

quantity := omit.Val[float32]{}
quantity.Set(3.0)
Is(v.OmitFloat32(quantity).Between(2.0, 6.0))

func (*ValidatorOmitFloat[T]) Context

func (validator *ValidatorOmitFloat[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitFloat[T]) EqualTo

func (validator *ValidatorOmitFloat[T]) EqualTo(value T, template ...string) *ValidatorOmitFloat[T]

Validate if an optional numeric value is equal to another. This function internally uses the golang `==` operator. The validation only passes if the value is set and equal to the provided value. For example:

quantity := omit.Val[float32]{}
quantity.Set(2.0)
Is(v.OmitFloat32(quantity).EqualTo(2.0))

func (*ValidatorOmitFloat[T]) Finite

func (validator *ValidatorOmitFloat[T]) Finite(template ...string) *ValidatorOmitFloat[T]

Validate if an optional numeric value is finite (not NaN and not infinite). The validation only passes if the value is set and is finite.

For example:

quantity := omit.Val[float32]{}
quantity.Set(3.14)
Is(v.OmitFloat32(quantity).Finite())

func (*ValidatorOmitFloat[T]) GreaterOrEqualTo

func (validator *ValidatorOmitFloat[T]) GreaterOrEqualTo(value T, template ...string) *ValidatorOmitFloat[T]

Validate if an optional numeric value is greater than or equal to another. This function internally uses the golang `>=` operator. The validation only passes if the value is set and greater than or equal to the provided value. For example:

quantity := omit.Val[float32]{}
quantity.Set(3.0)
Is(v.OmitFloat32(quantity).GreaterOrEqualTo(3.0))

func (*ValidatorOmitFloat[T]) GreaterThan

func (validator *ValidatorOmitFloat[T]) GreaterThan(value T, template ...string) *ValidatorOmitFloat[T]

Validate if an optional numeric value is greater than another. This function internally uses the golang `>` operator. The validation only passes if the value is set and greater than the provided value. For example:

quantity := omit.Val[float32]{}
quantity.Set(3.0)
Is(v.OmitFloat32(quantity).GreaterThan(2.0))

func (*ValidatorOmitFloat[T]) InSlice

func (validator *ValidatorOmitFloat[T]) InSlice(slice []T, template ...string) *ValidatorOmitFloat[T]

Validate if an optional number is present in a numeric slice. The validation only passes if the value is set and found in the provided slice. For example:

quantity := omit.Val[float32]{}
quantity.Set(3.0)
validQuantities := []float32{1.0, 3.0, 5.0}
Is(v.OmitFloat32(quantity).InSlice(validQuantities))

func (*ValidatorOmitFloat[T]) Infinite

func (validator *ValidatorOmitFloat[T]) Infinite(template ...string) *ValidatorOmitFloat[T]

Validate if an optional numeric value is infinite (positive or negative infinity). The validation only passes if the value is set and is infinite.

For example:

quantity := omit.Val[float32]{}
quantity.Set(float32(math.Inf(1)))
Is(v.OmitFloat32(quantity).Infinite())

func (*ValidatorOmitFloat[T]) LessOrEqualTo

func (validator *ValidatorOmitFloat[T]) LessOrEqualTo(value T, template ...string) *ValidatorOmitFloat[T]

Validate if an optional numeric value is less than or equal to another. This function internally uses the golang `<=` operator. The validation only passes if the value is set and less than or equal to the provided value. For example:

quantity := omit.Val[float32]{}
quantity.Set(2.0)
Is(v.OmitFloat32(quantity).LessOrEqualTo(2.0))

func (*ValidatorOmitFloat[T]) LessThan

func (validator *ValidatorOmitFloat[T]) LessThan(value T, template ...string) *ValidatorOmitFloat[T]

Validate if an optional numeric value is less than another. This function internally uses the golang `<` operator. The validation only passes if the value is set and less than the provided value. For example:

quantity := omit.Val[float32]{}
quantity.Set(2.0)
Is(v.OmitFloat32(quantity).LessThan(3.0))

func (*ValidatorOmitFloat[T]) NaN

func (validator *ValidatorOmitFloat[T]) NaN(template ...string) *ValidatorOmitFloat[T]

Validate if an optional numeric value is NaN (Not a Number). The validation only passes if the value is set and is NaN.

For example:

quantity := omit.Val[float32]{}
quantity.Set(float32(math.NaN()))
Is(v.OmitFloat32(quantity).NaN())

func (*ValidatorOmitFloat[T]) Negative

func (validator *ValidatorOmitFloat[T]) Negative(template ...string) *ValidatorOmitFloat[T]

Validate if an optional numeric value is negative (less than zero). The validation only passes if the value is set and less than zero.

For example:

quantity := omit.Val[float32]{}
quantity.Set(-5.5)
Is(v.OmitFloat32(quantity).Negative())

func (*ValidatorOmitFloat[T]) Not

func (validator *ValidatorOmitFloat[T]) Not() *ValidatorOmitFloat[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with the Zero() function
quantity := omit.Val[float32]{}
quantity.Set(0)
Is(v.OmitFloat32(quantity).Not().Zero()).Valid()

func (*ValidatorOmitFloat[T]) Or

func (validator *ValidatorOmitFloat[T]) Or() *ValidatorOmitFloat[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the input is Zero.
input := omit.Val[float32]{}
input.Set(0)
isValid := v.Is(v.OmitFloat32(input).GreaterThan(5).Or().Zero()).Valid()

func (*ValidatorOmitFloat[T]) Passing

func (validator *ValidatorOmitFloat[T]) Passing(function func(v omit.Val[T]) bool, template ...string) *ValidatorOmitFloat[T]

Validate if an optional numeric value passes a custom function. The validation only passes if the value is set and the custom function returns true. For example:

quantity := omit.Val[float32]{}
quantity.Set(2.0)
Is(v.OmitFloat32(quantity).Passing((v float32) bool {
	return v == getAllowedQuantity()
})

func (*ValidatorOmitFloat[T]) Positive

func (validator *ValidatorOmitFloat[T]) Positive(template ...string) *ValidatorOmitFloat[T]

Validate if an optional numeric value is positive (greater than zero). The validation only passes if the value is set and greater than zero.

For example:

quantity := omit.Val[float32]{}
quantity.Set(5.5)
Is(v.OmitFloat32(quantity).Positive())

func (*ValidatorOmitFloat[T]) Set

func (validator *ValidatorOmitFloat[T]) Set(template ...string) *ValidatorOmitFloat[T]

Validate if an optional numeric value is set. The validation only passes if the value is set. For example:

quantity := omit.Val[float32]{}
quantity.Set(5.0)
Is(v.OmitFloat32(quantity).Set())

func (*ValidatorOmitFloat[T]) Zero

func (validator *ValidatorOmitFloat[T]) Zero(template ...string) *ValidatorOmitFloat[T]

Validate if an optional numeric value is zero. The validation only passes if the value is set and equal to zero.

For example:

quantity := omit.Val[float32]{}
quantity.Set(0.0)
Is(v.OmitFloat32(quantity).Zero())

type ValidatorOmitInt

type ValidatorOmitInt[T ~int | ~int8 | ~int16 | ~int32 | ~int64] struct {
	// contains filtered or unexported fields
}

The ValidatorOmitInt provides functions for setting validation rules for optional int value types from the Opt library (omit.Val[T]), or a custom type based on a int, int8, int16, int32, or int64. These validators properly handle the optional nature of omit.Val[T] types, only validating when a value is set.

func OmitInt

func OmitInt[T ~int | ~int8 | ~int16 | ~int32 | ~int64](value omit.Val[T], nameAndTitle ...string) *ValidatorOmitInt[T]

Receives an optional int value (omit.Val[T]) to validate.

The value can also be a custom int type such as type Age int, wrapped in omit.Val. The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitInt8

func OmitInt8[T ~int8](value omit.Val[T], nameAndTitle ...string) *ValidatorOmitInt[T]

Receives an optional int8 value (omit.Val[T]) to validate.

The value can also be a custom int8 type such as type Age int8, wrapped in omit.Val. The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitInt16

func OmitInt16[T ~int16](value omit.Val[T], nameAndTitle ...string) *ValidatorOmitInt[T]

Receives an optional int16 value (omit.Val[T]) to validate.

The value can also be a custom int16 type such as type Age int16, wrapped in omit.Val. The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitInt32

func OmitInt32[T ~int32](value omit.Val[T], nameAndTitle ...string) *ValidatorOmitInt[T]

Receives an optional int32 value (omit.Val[T]) to validate.

The value can also be a custom int32 type such as type Age int32, wrapped in omit.Val. The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitInt64

func OmitInt64[T ~int64](value omit.Val[T], nameAndTitle ...string) *ValidatorOmitInt[T]

Receives an optional int64 value (omit.Val[T]) to validate.

The value can also be a custom int64 type such as type Age int64, wrapped in omit.Val. The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func (*ValidatorOmitInt[T]) Between

func (validator *ValidatorOmitInt[T]) Between(min T, max T, template ...string) *ValidatorOmitInt[T]

Validate if an optional number is within a range (inclusive). The validation only passes if the value is set and within the specified range. For example:

quantity := omit.Val[int]{}
quantity.Set(3)
Is(v.OmitInt(quantity).Between(2,6))

func (*ValidatorOmitInt[T]) Context

func (validator *ValidatorOmitInt[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitInt[T]) EqualTo

func (validator *ValidatorOmitInt[T]) EqualTo(value T, template ...string) *ValidatorOmitInt[T]

Validate if an optional numeric value is equal to another. This function internally uses the golang `==` operator. The validation only passes if the value is set and equal to the provided value. For example:

quantity := omit.Val[int]{}
quantity.Set(2)
Is(v.OmitInt(quantity).EqualTo(2))

func (*ValidatorOmitInt[T]) GreaterOrEqualTo

func (validator *ValidatorOmitInt[T]) GreaterOrEqualTo(value T, template ...string) *ValidatorOmitInt[T]

Validate if an optional numeric value is greater than or equal to another. This function internally uses the golang `>=` operator. The validation only passes if the value is set and greater than or equal to the provided value. For example:

quantity := omit.Val[int]{}
quantity.Set(3)
Is(v.OmitInt(quantity).GreaterOrEqualTo(3))

func (*ValidatorOmitInt[T]) GreaterThan

func (validator *ValidatorOmitInt[T]) GreaterThan(value T, template ...string) *ValidatorOmitInt[T]

Validate if an optional numeric value is greater than another. This function internally uses the golang `>` operator. The validation only passes if the value is set and greater than the provided value. For example:

quantity := omit.Val[int]{}
quantity.Set(3)
Is(v.OmitInt(quantity).GreaterThan(2))

func (*ValidatorOmitInt[T]) InSlice

func (validator *ValidatorOmitInt[T]) InSlice(slice []T, template ...string) *ValidatorOmitInt[T]

Validate if an optional number is present in a numeric slice. The validation only passes if the value is set and found in the provided slice. For example:

quantity := omit.Val[int]{}
quantity.Set(3)
validQuantities := []int{1,3,5}
Is(v.OmitInt(quantity).InSlice(validQuantities))

func (*ValidatorOmitInt[T]) LessOrEqualTo

func (validator *ValidatorOmitInt[T]) LessOrEqualTo(value T, template ...string) *ValidatorOmitInt[T]

Validate if an optional numeric value is less than or equal to another. This function internally uses the golang `<=` operator. The validation only passes if the value is set and less than or equal to the provided value. For example:

quantity := omit.Val[int]{}
quantity.Set(2)
Is(v.OmitInt(quantity).LessOrEqualTo(2))

func (*ValidatorOmitInt[T]) LessThan

func (validator *ValidatorOmitInt[T]) LessThan(value T, template ...string) *ValidatorOmitInt[T]

Validate if an optional numeric value is less than another. This function internally uses the golang `<` operator. The validation only passes if the value is set and less than the provided value. For example:

quantity := omit.Val[int]{}
quantity.Set(2)
Is(v.OmitInt(quantity).LessThan(3))

func (*ValidatorOmitInt[T]) Negative

func (validator *ValidatorOmitInt[T]) Negative(template ...string) *ValidatorOmitInt[T]

Validate if an optional numeric value is negative (less than zero). The validation only passes if the value is set and less than zero.

For example:

quantity := omit.Val[int]{}
quantity.Set(-5)
Is(v.OmitInt(quantity).Negative())

func (*ValidatorOmitInt[T]) Not

func (validator *ValidatorOmitInt[T]) Not() *ValidatorOmitInt[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with the Zero() function
quantity := omit.Val[int]{}
quantity.Set(0)
Is(v.OmitInt(quantity).Not().Zero()).Valid()

func (*ValidatorOmitInt[T]) Or

func (validator *ValidatorOmitInt[T]) Or() *ValidatorOmitInt[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the input is Zero.
input := omit.Val[int]{}
input.Set(0)
isValid := v.Is(v.OmitInt(input).GreaterThan(5).Or().Zero()).Valid()

func (*ValidatorOmitInt[T]) Passing

func (validator *ValidatorOmitInt[T]) Passing(function func(v omit.Val[T]) bool, template ...string) *ValidatorOmitInt[T]

Validate if an optional numeric value passes a custom function. The validation only passes if the value is set and the custom function returns true. For example:

quantity := omit.Val[int]{}
quantity.Set(2)
Is(v.OmitInt(quantity).Passing((v int) bool {
	return v == getAllowedQuantity()
})

func (*ValidatorOmitInt[T]) Positive

func (validator *ValidatorOmitInt[T]) Positive(template ...string) *ValidatorOmitInt[T]

Validate if an optional numeric value is positive (greater than zero). The validation only passes if the value is set and greater than zero.

For example:

quantity := omit.Val[int]{}
quantity.Set(5)
Is(v.OmitInt(quantity).Positive())

func (*ValidatorOmitInt[T]) Set

func (validator *ValidatorOmitInt[T]) Set(template ...string) *ValidatorOmitInt[T]

Validate if an optional numeric value is set. The validation only passes if the value is set. For example:

quantity := omit.Val[int]{}
quantity.Set(5)
Is(v.OmitInt(quantity).Set())

func (*ValidatorOmitInt[T]) Zero

func (validator *ValidatorOmitInt[T]) Zero(template ...string) *ValidatorOmitInt[T]

Validate if an optional numeric value is zero. The validation only passes if the value is set and equal to zero.

For example:

quantity := omit.Val[int]{}
quantity.Set(0)
Is(v.OmitInt(quantity).Zero())

type ValidatorOmitNullAny

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

The ValidatorOmitNullAny provides functions for setting validation rules for optional and nullable value types from the Opt library (omitnull.Val[any]). These validators properly handle the optional and nullable nature of omitnull.Val[any] types, only validating when a value is set and not null.

func OmitNullAny

func OmitNullAny(value omitnull.Val[any], nameAndTitle ...string) *ValidatorOmitNullAny

Receives an optional and nullable value (omitnull.Val[any]) to validate.

The value can be any type wrapped in omitnull.Val[any]. The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A value_%N pattern is used as a name in the error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name phone_number will be humanized as Phone Number.

func (*ValidatorOmitNullAny) Context

func (validator *ValidatorOmitNullAny) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitNullAny) EqualTo

func (validator *ValidatorOmitNullAny) EqualTo(value any, template ...string) *ValidatorOmitNullAny

Validate if an optional and nullable value is equal to another. This function uses reflection to compare values, which works for all types including incomparable types. The validation only passes if the value is set and not null and equal to the provided value. For example:

status := omitnull.Val[any]{}
status.Set("running")
Is(v.OmitNullAny(status).EqualTo("running"))

DEPRECATED: 'any' is not safely comparable. Use the OmitNullTyped validator instead. This function will be removed in Valgo v1.0.0.

func (*ValidatorOmitNullAny) Nil

func (validator *ValidatorOmitNullAny) Nil(template ...string) *ValidatorOmitNullAny

Validate if an optional and nullable value is nil. The validation passes if: - The omitnull.Val itself is null (using Null()), OR - The value inside is nil (for nil-able types like pointers, slices, maps, etc.)

For example:

nullVal := omitnull.Val[any]{}
nullVal.Null()
Is(v.OmitNullAny(nullVal).Nil())

var status *string
val := omitnull.Val[any]{}
val.Set(status)
Is(v.OmitNullAny(val).Nil())

func (*ValidatorOmitNullAny) Not

func (validator *ValidatorOmitNullAny) Not() *ValidatorOmitNullAny

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with the EqualTo() function
val := omitnull.Val[any]{}
val.Set("a")
Is(v.OmitNullAny(val).Not().EqualTo("a")).Valid()

func (*ValidatorOmitNullAny) Or

func (validator *ValidatorOmitNullAny) Or() *ValidatorOmitNullAny

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the value is equal to "test".
input := omitnull.Val[any]{}
input.Set("test")
isValid := v.Is(v.OmitNullAny(input).Passing(func(v any) bool { return v == nil }).Or().EqualTo("test")).Valid()

func (*ValidatorOmitNullAny) Passing

func (validator *ValidatorOmitNullAny) Passing(function func(v omitnull.Val[any]) bool, template ...string) *ValidatorOmitNullAny

Validate if an optional and nullable value passes a custom function. The validation only passes if the value is set and not null and the custom function returns true. For example:

status := omitnull.Val[any]{}
status.Set("")
Is(v.OmitNullAny(status).Passing((v any) bool {
	return v == getNewStatus()
})

func (*ValidatorOmitNullAny) Set

func (validator *ValidatorOmitNullAny) Set(template ...string) *ValidatorOmitNullAny

Validate if an optional and nullable value is set (not unset). The validation passes if the value is set, regardless of whether it's null or has a value.

For example:

user := omitnull.Val[any]{}
user.Set(User{Name: "John"})
Is(v.OmitNullAny(user).Set())

nullUser := omitnull.Val[any]{}
nullUser.Null()
Is(v.OmitNullAny(nullUser).Set())

type ValidatorOmitNullBoolean

type ValidatorOmitNullBoolean[T ~bool] struct {
	// contains filtered or unexported fields
}

The ValidatorOmitNullBoolean provides functions for setting validation rules for optional and nullable boolean value types from the Opt library (omitnull.Val[T]), or a custom type based on a bool. These validators properly handle the optional and nullable nature of omitnull.Val[T] types, only validating when a value is set and not null.

func OmitNullBoolean

func OmitNullBoolean[T ~bool](value omitnull.Val[T], nameAndTitle ...string) *ValidatorOmitNullBoolean[T]

Receives an optional and nullable boolean value (omitnull.Val[T]) to validate.

The value can also be a custom boolean type such as `type Active bool;`, wrapped in omitnull.Val. The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func (*ValidatorOmitNullBoolean[T]) Context

func (validator *ValidatorOmitNullBoolean[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitNullBoolean[T]) EqualTo

func (validator *ValidatorOmitNullBoolean[T]) EqualTo(value T, template ...string) *ValidatorOmitNullBoolean[T]

Validate if an optional and nullable boolean value is equal to another. The validation only passes if the value is set and not null and equal to the provided value. For example:

activated := omitnull.Val[bool]{}
activated.Set(true)
Is(v.OmitNullBoolean(activated).EqualTo(true))

func (*ValidatorOmitNullBoolean[T]) False

func (validator *ValidatorOmitNullBoolean[T]) False(template ...string) *ValidatorOmitNullBoolean[T]

Validate if an optional and nullable boolean value is false. The validation only passes if the value is set and not null and equal to false. For example:

activated := omitnull.Val[bool]{}
activated.Set(false)
Is(v.OmitNullBoolean(activated).False())

func (*ValidatorOmitNullBoolean[T]) FalseOrNil

func (validator *ValidatorOmitNullBoolean[T]) FalseOrNil(template ...string) *ValidatorOmitNullBoolean[T]

Validate if an optional and nullable boolean value is false or null. The validation only passes if the value is null or (set and not null and equal to false).

For example:

activated := omitnull.Val[bool]{}
activated.Set(false)
Is(v.OmitNullBoolean(activated).FalseOrNil())

nullActivated := omitnull.Val[bool]{}
nullActivated.SetNull()
Is(v.OmitNullBoolean(nullActivated).FalseOrNil())

func (*ValidatorOmitNullBoolean[T]) InSlice

func (validator *ValidatorOmitNullBoolean[T]) InSlice(slice []T, template ...string) *ValidatorOmitNullBoolean[T]

Validate if an optional and nullable boolean value is present in a boolean slice. The validation only passes if the value is set and not null and found in the provided slice. For example:

activated := omitnull.Val[bool]{}
activated.Set(false)
elements := []bool{true, false, true}
Is(v.OmitNullBoolean(activated).InSlice(elements))

func (*ValidatorOmitNullBoolean[T]) Nil

func (validator *ValidatorOmitNullBoolean[T]) Nil(template ...string) *ValidatorOmitNullBoolean[T]

Validate if an optional and nullable boolean value is null. The validation only passes if the value is null.

For example:

nullActivated := omitnull.Val[bool]{}
nullActivated.SetNull()
Is(v.OmitNullBoolean(nullActivated).Nil())

func (*ValidatorOmitNullBoolean[T]) Not

func (validator *ValidatorOmitNullBoolean[T]) Not() *ValidatorOmitNullBoolean[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because `Not()` inverts the boolean value associated with the True() function
activated := omitnull.Val[bool]{}
activated.Set(true)
Is(v.OmitNullBoolean(activated).Not().True()).Valid()

func (*ValidatorOmitNullBoolean[T]) Or

func (validator *ValidatorOmitNullBoolean[T]) Or() *ValidatorOmitNullBoolean[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the input is equals false.
input := omitnull.Val[bool]{}
input.Set(true)
isValid := v.Is(v.OmitNullBoolean(input).False().Or().True()).Valid()

func (*ValidatorOmitNullBoolean[T]) Passing

func (validator *ValidatorOmitNullBoolean[T]) Passing(function func(v omitnull.Val[T]) bool, template ...string) *ValidatorOmitNullBoolean[T]

Validate if an optional and nullable boolean value passes a custom function. The validation only passes if the value is set and not null and the custom function returns true. For example:

activated := omitnull.Val[bool]{}
activated.Set(false)
Is(v.OmitNullBoolean(activated).Passing((v bool) bool {
	return v == someBoolFunction()
})

func (*ValidatorOmitNullBoolean[T]) Set

func (validator *ValidatorOmitNullBoolean[T]) Set(template ...string) *ValidatorOmitNullBoolean[T]

Validate if an optional and nullable boolean value is set. The validation only passes if the value is set (regardless of whether it's null or not).

For example:

activated := omitnull.Val[bool]{}
activated.Set(true)
Is(v.OmitNullBoolean(activated).Set())

nullActivated := omitnull.Val[bool]{}
nullActivated.SetNull()
Is(v.OmitNullBoolean(nullActivated).Set())

func (*ValidatorOmitNullBoolean[T]) True

func (validator *ValidatorOmitNullBoolean[T]) True(template ...string) *ValidatorOmitNullBoolean[T]

Validate if an optional and nullable boolean value is true. The validation only passes if the value is set and not null and equal to true. For example:

activated := omitnull.Val[bool]{}
activated.Set(true)
Is(v.OmitNullBoolean(activated).True())

type ValidatorOmitNullComparable

type ValidatorOmitNullComparable[T comparable] struct {
	// contains filtered or unexported fields
}

The ValidatorOmitNullComparable provides functions for setting validation rules for optional and nullable comparable value types from the Opt library (omitnull.Val[T]). T can be any Go type (pointer, struct, etc.) that is comparable. These validators properly handle the optional and nullable nature of omitnull.Val[T] types, only validating when a value is set and not null.

func OmitNullComparable

func OmitNullComparable[T comparable](value omitnull.Val[T], nameAndTitle ...string) *ValidatorOmitNullComparable[T]

Receives an optional and nullable comparable value (omitnull.Val[T]) to validate, where T must be comparable.

The value can be any Go type (pointer, struct, etc.) that is comparable, wrapped in omitnull.Val. The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A value_%N pattern is used as a name in the error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name phone_number will be humanized as Phone Number.

Example:

status := omitnull.Val[string]{}
status.Set("running")
v.Is(v.OmitNullComparable(status).Not().EqualTo("stopped"))

func (*ValidatorOmitNullComparable[T]) Context

func (validator *ValidatorOmitNullComparable[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitNullComparable[T]) EqualTo

func (validator *ValidatorOmitNullComparable[T]) EqualTo(value T, template ...string) *ValidatorOmitNullComparable[T]

Validate if an optional and nullable value is equal to another. This function internally uses the golang `==` operator. The validation only passes if the value is set and not null and equal to the provided value. For example:

status := omitnull.Val[string]{}
status.Set("running")
Is(v.OmitNullComparable(status).EqualTo("running"))

func (*ValidatorOmitNullComparable[T]) InSlice

func (validator *ValidatorOmitNullComparable[T]) InSlice(slice []T, template ...string) *ValidatorOmitNullComparable[T]

Validate if an optional and nullable value is present in a slice. The validation only passes if the value is set and not null and found in the provided slice. For example:

status := omitnull.Val[string]{}
status.Set("idle")
validStatus := []string{"idle", "paused", "stopped"}
Is(v.OmitNullComparable(status).InSlice(validStatus))

func (*ValidatorOmitNullComparable[T]) Nil

func (validator *ValidatorOmitNullComparable[T]) Nil(template ...string) *ValidatorOmitNullComparable[T]

Validate if an optional and nullable value is null. The validation only passes if the value is null.

For example:

nullStatus := omitnull.Val[string]{}
nullStatus.Null()
Is(v.OmitNullComparable(nullStatus).Nil())

func (*ValidatorOmitNullComparable[T]) Not

Invert the logical value associated with the next validator function. For example:

// It will return false because `Not()` inverts the boolean value associated with `EqualTo()`
val := omitnull.Val[string]{}
val.Set("a")
v.Is(v.OmitNullComparable(val).Not().EqualTo("a")).Valid()

func (*ValidatorOmitNullComparable[T]) Or

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the string is equals "running".
status := omitnull.Val[string]{}
status.Set("running")
isValid := v.Is(v.OmitNullComparable(status).EqualTo("paused").Or().EqualTo("running")).Valid()

func (*ValidatorOmitNullComparable[T]) Passing

func (validator *ValidatorOmitNullComparable[T]) Passing(function func(v omitnull.Val[T]) bool, template ...string) *ValidatorOmitNullComparable[T]

Validate if an optional and nullable value passes a custom function. The function receives a typed T value, enabling compile-time type safety. The validation only passes if the value is set and not null and the custom function returns true.

For example:

type Status string
status := omitnull.Val[Status]{}
status.Set(Status("running"))
isValid := v.Is(
  v.OmitNullComparable(status).Passing(func(s Status) bool {
    return s == "running" || s == "paused"
  }),
).Valid()

func (*ValidatorOmitNullComparable[T]) Set

func (validator *ValidatorOmitNullComparable[T]) Set(template ...string) *ValidatorOmitNullComparable[T]

Validate if an optional and nullable value is set (not unset). The validation passes if the value is set, regardless of whether it's null or has a value.

For example:

status := omitnull.Val[string]{}
status.Set("running")
Is(v.OmitNullComparable(status).Set())

nullStatus := omitnull.Val[string]{}
nullStatus.Null()
Is(v.OmitNullComparable(nullStatus).Set())

type ValidatorOmitNullFloat

type ValidatorOmitNullFloat[T ~float32 | ~float64] struct {
	// contains filtered or unexported fields
}

The ValidatorOmitNullFloat provides functions for setting validation rules for optional and nullable float value types from the Opt library (omitnull.Val[T]), or a custom type based on a float32 or float64. These validators properly handle the optional and nullable nature of omitnull.Val[T] types, only validating when a value is set and not null.

func OmitNullFloat32

func OmitNullFloat32[T ~float32](value omitnull.Val[T], nameAndTitle ...string) *ValidatorOmitNullFloat[T]

Receives an optional and nullable float32 value (omitnull.Val[T]) to validate.

The value can also be a custom float32 type such as type Price float32, wrapped in omitnull.Val. The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitNullFloat64

func OmitNullFloat64[T ~float64](value omitnull.Val[T], nameAndTitle ...string) *ValidatorOmitNullFloat[T]

Receives an optional and nullable float64 value (omitnull.Val[T]) to validate.

The value can also be a custom float64 type such as type Price float64, wrapped in omitnull.Val. The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func (*ValidatorOmitNullFloat[T]) Between

func (validator *ValidatorOmitNullFloat[T]) Between(min T, max T, template ...string) *ValidatorOmitNullFloat[T]

Validate if an optional and nullable number is within a range (inclusive). The validation only passes if the value is set and not null and within the specified range. For example:

quantity := omitnull.Val[float32]{}
quantity.Set(3.0)
Is(v.OmitNullFloat32(quantity).Between(2.0, 6.0))

func (*ValidatorOmitNullFloat[T]) Context

func (validator *ValidatorOmitNullFloat[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitNullFloat[T]) EqualTo

func (validator *ValidatorOmitNullFloat[T]) EqualTo(value T, template ...string) *ValidatorOmitNullFloat[T]

Validate if an optional and nullable numeric value is equal to another. This function internally uses the golang `==` operator. The validation only passes if the value is set and not null and equal to the provided value. For example:

quantity := omitnull.Val[float32]{}
quantity.Set(2.0)
Is(v.OmitNullFloat32(quantity).EqualTo(2.0))

func (*ValidatorOmitNullFloat[T]) Finite

func (validator *ValidatorOmitNullFloat[T]) Finite(template ...string) *ValidatorOmitNullFloat[T]

Validate if an optional and nullable numeric value is finite (not NaN and not infinite). The validation only passes if the value is set and not null and is finite.

For example:

quantity := omitnull.Val[float32]{}
quantity.Set(3.14)
Is(v.OmitNullFloat32(quantity).Finite())

func (*ValidatorOmitNullFloat[T]) GreaterOrEqualTo

func (validator *ValidatorOmitNullFloat[T]) GreaterOrEqualTo(value T, template ...string) *ValidatorOmitNullFloat[T]

Validate if an optional and nullable numeric value is greater than or equal to another. This function internally uses the golang `>=` operator. The validation only passes if the value is set and not null and greater than or equal to the provided value. For example:

quantity := omitnull.Val[float32]{}
quantity.Set(3.0)
Is(v.OmitNullFloat32(quantity).GreaterOrEqualTo(3.0))

func (*ValidatorOmitNullFloat[T]) GreaterThan

func (validator *ValidatorOmitNullFloat[T]) GreaterThan(value T, template ...string) *ValidatorOmitNullFloat[T]

Validate if an optional and nullable numeric value is greater than another. This function internally uses the golang `>` operator. The validation only passes if the value is set and not null and greater than the provided value. For example:

quantity := omitnull.Val[float32]{}
quantity.Set(3.0)
Is(v.OmitNullFloat32(quantity).GreaterThan(2.0))

func (*ValidatorOmitNullFloat[T]) InSlice

func (validator *ValidatorOmitNullFloat[T]) InSlice(slice []T, template ...string) *ValidatorOmitNullFloat[T]

Validate if an optional and nullable number is present in a numeric slice. The validation only passes if the value is set and not null and found in the provided slice. For example:

quantity := omitnull.Val[float32]{}
quantity.Set(3.0)
validQuantities := []float32{1.0, 3.0, 5.0}
Is(v.OmitNullFloat32(quantity).InSlice(validQuantities))

func (*ValidatorOmitNullFloat[T]) Infinite

func (validator *ValidatorOmitNullFloat[T]) Infinite(template ...string) *ValidatorOmitNullFloat[T]

Validate if an optional and nullable numeric value is infinite (positive or negative infinity). The validation only passes if the value is set and not null and is infinite.

For example:

quantity := omitnull.Val[float32]{}
quantity.Set(float32(math.Inf(1)))
Is(v.OmitNullFloat32(quantity).Infinite())

func (*ValidatorOmitNullFloat[T]) LessOrEqualTo

func (validator *ValidatorOmitNullFloat[T]) LessOrEqualTo(value T, template ...string) *ValidatorOmitNullFloat[T]

Validate if an optional and nullable numeric value is less than or equal to another. This function internally uses the golang `<=` operator. The validation only passes if the value is set and not null and less than or equal to the provided value. For example:

quantity := omitnull.Val[float32]{}
quantity.Set(2.0)
Is(v.OmitNullFloat32(quantity).LessOrEqualTo(2.0))

func (*ValidatorOmitNullFloat[T]) LessThan

func (validator *ValidatorOmitNullFloat[T]) LessThan(value T, template ...string) *ValidatorOmitNullFloat[T]

Validate if an optional and nullable numeric value is less than another. This function internally uses the golang `<` operator. The validation only passes if the value is set and not null and less than the provided value. For example:

quantity := omitnull.Val[float32]{}
quantity.Set(2.0)
Is(v.OmitNullFloat32(quantity).LessThan(3.0))

func (*ValidatorOmitNullFloat[T]) NaN

func (validator *ValidatorOmitNullFloat[T]) NaN(template ...string) *ValidatorOmitNullFloat[T]

Validate if an optional and nullable numeric value is NaN (Not a Number). The validation only passes if the value is set and not null and is NaN.

For example:

quantity := omitnull.Val[float32]{}
quantity.Set(float32(math.NaN()))
Is(v.OmitNullFloat32(quantity).NaN())

func (*ValidatorOmitNullFloat[T]) Negative

func (validator *ValidatorOmitNullFloat[T]) Negative(template ...string) *ValidatorOmitNullFloat[T]

Validate if an optional and nullable numeric value is negative (less than zero). The validation only passes if the value is set and not null and less than zero.

For example:

quantity := omitnull.Val[float32]{}
quantity.Set(-5.5)
Is(v.OmitNullFloat32(quantity).Negative())

func (*ValidatorOmitNullFloat[T]) Nil

func (validator *ValidatorOmitNullFloat[T]) Nil(template ...string) *ValidatorOmitNullFloat[T]

Validate if an optional and nullable numeric value is null. The validation only passes if the value is null.

For example:

nullQuantity := omitnull.Val[float32]{}
nullQuantity.Null()
Is(v.OmitNullFloat32(nullQuantity).Nil())

func (*ValidatorOmitNullFloat[T]) Not

func (validator *ValidatorOmitNullFloat[T]) Not() *ValidatorOmitNullFloat[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with the Zero() function
quantity := omitnull.Val[float32]{}
quantity.Set(0.0)
Is(v.OmitNullFloat32(quantity).Not().Zero()).Valid()

func (*ValidatorOmitNullFloat[T]) Or

func (validator *ValidatorOmitNullFloat[T]) Or() *ValidatorOmitNullFloat[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the input is Zero.
input := omitnull.Val[float32]{}
input.Set(0.0)
isValid := v.Is(v.OmitNullFloat32(input).GreaterThan(5.0).Or().Zero()).Valid()

func (*ValidatorOmitNullFloat[T]) Passing

func (validator *ValidatorOmitNullFloat[T]) Passing(function func(v omitnull.Val[T]) bool, template ...string) *ValidatorOmitNullFloat[T]

Validate if an optional and nullable numeric value passes a custom function. The validation only passes if the value is set and not null and the custom function returns true. For example:

quantity := omitnull.Val[float32]{}
quantity.Set(2.0)
Is(v.OmitNullFloat32(quantity).Passing((v float32) bool {
	return v == getAllowedQuantity()
})

func (*ValidatorOmitNullFloat[T]) Positive

func (validator *ValidatorOmitNullFloat[T]) Positive(template ...string) *ValidatorOmitNullFloat[T]

Validate if an optional and nullable numeric value is positive (greater than zero). The validation only passes if the value is set and not null and greater than zero.

For example:

quantity := omitnull.Val[float32]{}
quantity.Set(5.5)
Is(v.OmitNullFloat32(quantity).Positive())

func (*ValidatorOmitNullFloat[T]) Set

func (validator *ValidatorOmitNullFloat[T]) Set(template ...string) *ValidatorOmitNullFloat[T]

Validate if an optional and nullable numeric value is set (not unset). The validation only passes if the value is set (either has a value or is null, but not unset). For example:

quantity := omitnull.Val[float32]{}
quantity.Set(5.0)
Is(v.OmitNullFloat32(quantity).Set())

nullQuantity := omitnull.Val[float32]{}
nullQuantity.Null()
Is(v.OmitNullFloat32(nullQuantity).Set())

func (*ValidatorOmitNullFloat[T]) Zero

func (validator *ValidatorOmitNullFloat[T]) Zero(template ...string) *ValidatorOmitNullFloat[T]

Validate if an optional and nullable numeric value is zero. The validation only passes if the value is set and not null and equal to zero.

For example:

quantity := omitnull.Val[float32]{}
quantity.Set(0.0)
Is(v.OmitNullFloat32(quantity).Zero())

func (*ValidatorOmitNullFloat[T]) ZeroOrNil

func (validator *ValidatorOmitNullFloat[T]) ZeroOrNil(template ...string) *ValidatorOmitNullFloat[T]

Validate if an optional and nullable numeric value is zero or null. The validation passes if the value is null or (set and not null and equal to zero).

For example:

quantity := omitnull.Val[float32]{}
quantity.Set(0.0)
Is(v.OmitNullFloat32(quantity).ZeroOrNil())

nullQuantity := omitnull.Val[float32]{}
nullQuantity.Null()
Is(v.OmitNullFloat32(nullQuantity).ZeroOrNil())

type ValidatorOmitNullInt

type ValidatorOmitNullInt[T ~int | ~int8 | ~int16 | ~int32 | ~int64] struct {
	// contains filtered or unexported fields
}

The ValidatorOmitNullInt provides functions for setting validation rules for optional and nullable int value types from the Opt library (omitnull.Val[T]), or a custom type based on a int, int8, int16, int32, or int64. These validators properly handle the optional and nullable nature of omitnull.Val[T] types, only validating when a value is set and not null.

func OmitNullInt

func OmitNullInt[T ~int | ~int8 | ~int16 | ~int32 | ~int64](value omitnull.Val[T], nameAndTitle ...string) *ValidatorOmitNullInt[T]

Receives an optional and nullable int value (omitnull.Val[T]) to validate.

The value can also be a custom int type such as type Age int, wrapped in omitnull.Val. The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitNullInt8

func OmitNullInt8[T ~int8](value omitnull.Val[T], nameAndTitle ...string) *ValidatorOmitNullInt[T]

Receives an optional and nullable int8 value (omitnull.Val[T]) to validate.

The value can also be a custom int8 type such as type Age int8, wrapped in omitnull.Val. The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitNullInt16

func OmitNullInt16[T ~int16](value omitnull.Val[T], nameAndTitle ...string) *ValidatorOmitNullInt[T]

Receives an optional and nullable int16 value (omitnull.Val[T]) to validate.

The value can also be a custom int16 type such as type Age int16, wrapped in omitnull.Val. The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitNullInt32

func OmitNullInt32[T ~int32](value omitnull.Val[T], nameAndTitle ...string) *ValidatorOmitNullInt[T]

Receives an optional and nullable int32 value (omitnull.Val[T]) to validate.

The value can also be a custom int32 type such as type Age int32, wrapped in omitnull.Val. The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitNullInt64

func OmitNullInt64[T ~int64](value omitnull.Val[T], nameAndTitle ...string) *ValidatorOmitNullInt[T]

Receives an optional and nullable int64 value (omitnull.Val[T]) to validate.

The value can also be a custom int64 type such as type Age int64, wrapped in omitnull.Val. The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func (*ValidatorOmitNullInt[T]) Between

func (validator *ValidatorOmitNullInt[T]) Between(min T, max T, template ...string) *ValidatorOmitNullInt[T]

Validate if an optional and nullable number is within a range (inclusive). The validation only passes if the value is set and not null and within the specified range. For example:

quantity := omitnull.Val[int]{}
quantity.Set(3)
Is(v.OmitNullInt(quantity).Between(2,6))

func (*ValidatorOmitNullInt[T]) Context

func (validator *ValidatorOmitNullInt[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitNullInt[T]) EqualTo

func (validator *ValidatorOmitNullInt[T]) EqualTo(value T, template ...string) *ValidatorOmitNullInt[T]

Validate if an optional and nullable numeric value is equal to another. This function internally uses the golang `==` operator. The validation only passes if the value is set and not null and equal to the provided value. For example:

quantity := omitnull.Val[int]{}
quantity.Set(2)
Is(v.OmitNullInt(quantity).EqualTo(2))

func (*ValidatorOmitNullInt[T]) GreaterOrEqualTo

func (validator *ValidatorOmitNullInt[T]) GreaterOrEqualTo(value T, template ...string) *ValidatorOmitNullInt[T]

Validate if an optional and nullable numeric value is greater than or equal to another. This function internally uses the golang `>=` operator. The validation only passes if the value is set and not null and greater than or equal to the provided value. For example:

quantity := omitnull.Val[int]{}
quantity.Set(3)
Is(v.OmitNullInt(quantity).GreaterOrEqualTo(3))

func (*ValidatorOmitNullInt[T]) GreaterThan

func (validator *ValidatorOmitNullInt[T]) GreaterThan(value T, template ...string) *ValidatorOmitNullInt[T]

Validate if an optional and nullable numeric value is greater than another. This function internally uses the golang `>` operator. The validation only passes if the value is set and not null and greater than the provided value. For example:

quantity := omitnull.Val[int]{}
quantity.Set(3)
Is(v.OmitNullInt(quantity).GreaterThan(2))

func (*ValidatorOmitNullInt[T]) InSlice

func (validator *ValidatorOmitNullInt[T]) InSlice(slice []T, template ...string) *ValidatorOmitNullInt[T]

Validate if an optional and nullable number is present in a numeric slice. The validation only passes if the value is set and not null and found in the provided slice. For example:

quantity := omitnull.Val[int]{}
quantity.Set(3)
validQuantities := []int{1,3,5}
Is(v.OmitNullInt(quantity).InSlice(validQuantities))

func (*ValidatorOmitNullInt[T]) LessOrEqualTo

func (validator *ValidatorOmitNullInt[T]) LessOrEqualTo(value T, template ...string) *ValidatorOmitNullInt[T]

Validate if an optional and nullable numeric value is less than or equal to another. This function internally uses the golang `<=` operator. The validation only passes if the value is set and not null and less than or equal to the provided value. For example:

quantity := omitnull.Val[int]{}
quantity.Set(2)
Is(v.OmitNullInt(quantity).LessOrEqualTo(2))

func (*ValidatorOmitNullInt[T]) LessThan

func (validator *ValidatorOmitNullInt[T]) LessThan(value T, template ...string) *ValidatorOmitNullInt[T]

Validate if an optional and nullable numeric value is less than another. This function internally uses the golang `<` operator. The validation only passes if the value is set and not null and less than the provided value. For example:

quantity := omitnull.Val[int]{}
quantity.Set(2)
Is(v.OmitNullInt(quantity).LessThan(3))

func (*ValidatorOmitNullInt[T]) Negative

func (validator *ValidatorOmitNullInt[T]) Negative(template ...string) *ValidatorOmitNullInt[T]

Validate if an optional and nullable numeric value is negative (less than zero). The validation only passes if the value is set and not null and less than zero.

For example:

quantity := omitnull.Val[int]{}
quantity.Set(-5)
Is(v.OmitNullInt(quantity).Negative())

func (*ValidatorOmitNullInt[T]) Nil

func (validator *ValidatorOmitNullInt[T]) Nil(template ...string) *ValidatorOmitNullInt[T]

Validate if an optional and nullable numeric value is null. The validation only passes if the value is null.

For example:

nullQuantity := omitnull.Val[int]{}
nullQuantity.Null()
Is(v.OmitNullInt(nullQuantity).Nil())

func (*ValidatorOmitNullInt[T]) Not

func (validator *ValidatorOmitNullInt[T]) Not() *ValidatorOmitNullInt[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with the Zero() function
quantity := omitnull.Val[int]{}
quantity.Set(0)
Is(v.OmitNullInt(quantity).Not().Zero()).Valid()

func (*ValidatorOmitNullInt[T]) Or

func (validator *ValidatorOmitNullInt[T]) Or() *ValidatorOmitNullInt[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the input is Zero.
input := omitnull.Val[int]{}
input.Set(0)
isValid := v.Is(v.OmitNullInt(input).GreaterThan(5).Or().Zero()).Valid()

func (*ValidatorOmitNullInt[T]) Passing

func (validator *ValidatorOmitNullInt[T]) Passing(function func(v omitnull.Val[T]) bool, template ...string) *ValidatorOmitNullInt[T]

Validate if an optional and nullable numeric value passes a custom function. The validation only passes if the value is set and not null and the custom function returns true. For example:

quantity := omitnull.Val[int]{}
quantity.Set(2)
Is(v.OmitNullInt(quantity).Passing((v int) bool {
	return v == getAllowedQuantity()
})

func (*ValidatorOmitNullInt[T]) Positive

func (validator *ValidatorOmitNullInt[T]) Positive(template ...string) *ValidatorOmitNullInt[T]

Validate if an optional and nullable numeric value is positive (greater than zero). The validation only passes if the value is set and not null and greater than zero.

For example:

quantity := omitnull.Val[int]{}
quantity.Set(5)
Is(v.OmitNullInt(quantity).Positive())

func (*ValidatorOmitNullInt[T]) Set

func (validator *ValidatorOmitNullInt[T]) Set(template ...string) *ValidatorOmitNullInt[T]

Validate if an optional and nullable numeric value is set (not unset). The validation only passes if the value is set (either has a value or is null, but not unset). For example:

quantity := omitnull.Val[int]{}
quantity.Set(5)
Is(v.OmitNullInt(quantity).Set())

nullQuantity := omitnull.Val[int]{}
nullQuantity.Null()
Is(v.OmitNullInt(nullQuantity).Set())

func (*ValidatorOmitNullInt[T]) Zero

func (validator *ValidatorOmitNullInt[T]) Zero(template ...string) *ValidatorOmitNullInt[T]

Validate if an optional and nullable numeric value is zero. The validation only passes if the value is set and not null and equal to zero.

For example:

quantity := omitnull.Val[int]{}
quantity.Set(0)
Is(v.OmitNullInt(quantity).Zero())

func (*ValidatorOmitNullInt[T]) ZeroOrNil

func (validator *ValidatorOmitNullInt[T]) ZeroOrNil(template ...string) *ValidatorOmitNullInt[T]

Validate if an optional and nullable numeric value is zero or null. The validation passes if the value is null or (set and not null and equal to zero).

For example:

quantity := omitnull.Val[int]{}
quantity.Set(0)
Is(v.OmitNullInt(quantity).ZeroOrNil())

nullQuantity := omitnull.Val[int]{}
nullQuantity.Null()
Is(v.OmitNullInt(nullQuantity).ZeroOrNil())

type ValidatorOmitNullNumber

type ValidatorOmitNullNumber[T TypeNumber] struct {
	// contains filtered or unexported fields
}

The ValidatorOmitNullNumber provides functions for setting validation rules for optional and nullable numeric value types from the Opt library (omitnull.Val[T]), or a custom type based on a TypeNumber. These validators properly handle the optional and nullable nature of omitnull.Val[T] types, only validating when a value is set and not null.

func OmitNullNumber

func OmitNullNumber[T TypeNumber](value omitnull.Val[T], nameAndTitle ...string) *ValidatorOmitNullNumber[T]

Receives an optional and nullable numeric value (omitnull.Val[T]) to validate.

The value can be any golang numeric type (int64, int32, float32, uint, etc.) or a custom numeric type such as `type Level int32;`, wrapped in omitnull.Val. The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func (*ValidatorOmitNullNumber[T]) Between

func (validator *ValidatorOmitNullNumber[T]) Between(min T, max T, template ...string) *ValidatorOmitNullNumber[T]

Validate if an optional and nullable number is within a range (inclusive). The validation only passes if the value is set and not null and within the specified range. For example:

quantity := omitnull.Val[int]{}
quantity.Set(3)
Is(v.OmitNullNumber(quantity).Between(2,6))

func (*ValidatorOmitNullNumber[T]) Context

func (validator *ValidatorOmitNullNumber[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitNullNumber[T]) EqualTo

func (validator *ValidatorOmitNullNumber[T]) EqualTo(value T, template ...string) *ValidatorOmitNullNumber[T]

Validate if an optional and nullable numeric value is equal to another. This function internally uses the golang `==` operator. The validation only passes if the value is set and not null and equal to the provided value. For example:

quantity := omitnull.Val[int]{}
quantity.Set(2)
Is(v.OmitNullNumber(quantity).EqualTo(2))

func (*ValidatorOmitNullNumber[T]) GreaterOrEqualTo

func (validator *ValidatorOmitNullNumber[T]) GreaterOrEqualTo(value T, template ...string) *ValidatorOmitNullNumber[T]

Validate if an optional and nullable numeric value is greater than or equal to another. This function internally uses the golang `>=` operator. The validation only passes if the value is set and not null and greater than or equal to the provided value. For example:

quantity := omitnull.Val[int]{}
quantity.Set(3)
Is(v.OmitNullNumber(quantity).GreaterOrEqualTo(3))

func (*ValidatorOmitNullNumber[T]) GreaterThan

func (validator *ValidatorOmitNullNumber[T]) GreaterThan(value T, template ...string) *ValidatorOmitNullNumber[T]

Validate if an optional and nullable numeric value is greater than another. This function internally uses the golang `>` operator. The validation only passes if the value is set and not null and greater than the provided value. For example:

quantity := omitnull.Val[int]{}
quantity.Set(3)
Is(v.OmitNullNumber(quantity).GreaterThan(2))

func (*ValidatorOmitNullNumber[T]) InSlice

func (validator *ValidatorOmitNullNumber[T]) InSlice(slice []T, template ...string) *ValidatorOmitNullNumber[T]

Validate if an optional and nullable number is present in a numeric slice. The validation only passes if the value is set and not null and found in the provided slice. For example:

quantity := omitnull.Val[int]{}
quantity.Set(3)
validQuantities := []int{1,3,5}
Is(v.OmitNullNumber(quantity).InSlice(validQuantities))

func (*ValidatorOmitNullNumber[T]) LessOrEqualTo

func (validator *ValidatorOmitNullNumber[T]) LessOrEqualTo(value T, template ...string) *ValidatorOmitNullNumber[T]

Validate if an optional and nullable numeric value is less than or equal to another. This function internally uses the golang `<=` operator. The validation only passes if the value is set and not null and less than or equal to the provided value. For example:

quantity := omitnull.Val[int]{}
quantity.Set(2)
Is(v.OmitNullNumber(quantity).LessOrEqualTo(2))

func (*ValidatorOmitNullNumber[T]) LessThan

func (validator *ValidatorOmitNullNumber[T]) LessThan(value T, template ...string) *ValidatorOmitNullNumber[T]

Validate if an optional and nullable numeric value is less than another. This function internally uses the golang `<` operator. The validation only passes if the value is set and not null and less than the provided value. For example:

quantity := omitnull.Val[int]{}
quantity.Set(2)
Is(v.OmitNullNumber(quantity).LessThan(3))

func (*ValidatorOmitNullNumber[T]) Nil

func (validator *ValidatorOmitNullNumber[T]) Nil(template ...string) *ValidatorOmitNullNumber[T]

Validate if an optional and nullable numeric value is null. The validation only passes if the value is null.

For example:

nullQuantity := omitnull.Val[int]{}
nullQuantity.Null()
Is(v.OmitNullNumber(nullQuantity).Nil())

func (*ValidatorOmitNullNumber[T]) Not

func (validator *ValidatorOmitNullNumber[T]) Not() *ValidatorOmitNullNumber[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with the Zero() function
quantity := omitnull.Val[int]{}
quantity.Set(0)
Is(v.OmitNullNumber(quantity).Not().Zero()).Valid()

func (*ValidatorOmitNullNumber[T]) Or

func (validator *ValidatorOmitNullNumber[T]) Or() *ValidatorOmitNullNumber[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the input is Zero.
input := omitnull.Val[int]{}
input.Set(0)
isValid := v.Is(v.OmitNullNumber(input).GreaterThan(5).Or().Zero()).Valid()

func (*ValidatorOmitNullNumber[T]) Passing

func (validator *ValidatorOmitNullNumber[T]) Passing(function func(v omitnull.Val[T]) bool, template ...string) *ValidatorOmitNullNumber[T]

Validate if an optional and nullable numeric value passes a custom function. The validation only passes if the value is set and not null and the custom function returns true. For example:

quantity := omitnull.Val[int]{}
quantity.Set(2)
Is(v.OmitNullNumber(quantity).Passing((v int) bool {
	return v == getAllowedQuantity()
})

func (*ValidatorOmitNullNumber[T]) Set

func (validator *ValidatorOmitNullNumber[T]) Set(template ...string) *ValidatorOmitNullNumber[T]

Validate if an optional and nullable numeric value is set (not unset). The validation only passes if the value is set (either has a value or is null, but not unset). For example:

quantity := omitnull.Val[int]{}
quantity.Set(5)
Is(v.OmitNullNumber(quantity).Set())

nullQuantity := omitnull.Val[int]{}
nullQuantity.Null()
Is(v.OmitNullNumber(nullQuantity).Set())

func (*ValidatorOmitNullNumber[T]) Zero

func (validator *ValidatorOmitNullNumber[T]) Zero(template ...string) *ValidatorOmitNullNumber[T]

Validate if an optional and nullable numeric value is zero. The validation only passes if the value is set and not null and equal to zero.

For example:

quantity := omitnull.Val[int]{}
quantity.Set(0)
Is(v.OmitNullNumber(quantity).Zero())

func (*ValidatorOmitNullNumber[T]) ZeroOrNil

func (validator *ValidatorOmitNullNumber[T]) ZeroOrNil(template ...string) *ValidatorOmitNullNumber[T]

Validate if an optional and nullable numeric value is zero or null. The validation passes if the value is null or (set and not null and equal to zero).

For example:

quantity := omitnull.Val[int]{}
quantity.Set(0)
Is(v.OmitNullNumber(quantity).ZeroOrNil())

nullQuantity := omitnull.Val[int]{}
nullQuantity.Null()
Is(v.OmitNullNumber(nullQuantity).ZeroOrNil())

type ValidatorOmitNullString

type ValidatorOmitNullString[T ~string] struct {
	// contains filtered or unexported fields
}

The ValidatorOmitNullString provides functions for setting validation rules for optional and nullable string value types from the Opt library (omitnull.Val[T]), or a custom type based on a string. These validators properly handle the optional and nullable nature of omitnull.Val[T] types, only validating when a value is set and not null.

func OmitNullString

func OmitNullString[T ~string](value omitnull.Val[T], nameAndTitle ...string) *ValidatorOmitNullString[T]

Receives an optional and nullable string value (omitnull.Val[T]) to validate.

The value can also be a custom string type such as type Status string, wrapped in omitnull.Val. The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func (*ValidatorOmitNullString[T]) Between

func (validator *ValidatorOmitNullString[T]) Between(min T, max T, template ...string) *ValidatorOmitNullString[T]

Validate if the value of an optional and nullable string is within a range (inclusive). The validation only passes if the value is set and not null and within the specified range. For example:

slug := omitnull.Val[string]{}
slug.Set("ab")
Is(v.OmitNullString(slug).Between("ab", "ac"))

func (*ValidatorOmitNullString[T]) Blank

func (validator *ValidatorOmitNullString[T]) Blank(template ...string) *ValidatorOmitNullString[T]

Validate if an optional and nullable string value is blank. Blank will be true if the length of the string is zero or if the string only has spaces. The validation only passes if the value is set and not null and blank. For example:

status := omitnull.Val[string]{}
status.Set("")
Is(v.OmitNullString(status).Blank()) // Will be true

status2 := omitnull.Val[string]{}
status2.Set(" ")
Is(v.OmitNullString(status2).Blank()) // Will be true

func (*ValidatorOmitNullString[T]) Context

func (validator *ValidatorOmitNullString[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitNullString[T]) Empty

func (validator *ValidatorOmitNullString[T]) Empty(template ...string) *ValidatorOmitNullString[T]

Validate if an optional and nullable string value is empty. Return false if the length of the string is greater than zero, even if the string has only spaces. The validation only passes if the value is set and not null and empty.

For checking if the string has only spaces, use the function `Blank()` instead. For example:

status := omitnull.Val[string]{}
status.Set("")
Is(v.OmitNullString(status).Empty()) // Will be true

func (*ValidatorOmitNullString[T]) EmptyOrNil

func (validator *ValidatorOmitNullString[T]) EmptyOrNil(template ...string) *ValidatorOmitNullString[T]

Validate if an optional and nullable string value is empty or null. The validation passes if the value is null or (set and not null and equal to an empty string).

For example:

status := omitnull.Val[string]{}
status.Set("")
Is(v.OmitNullString(status).EmptyOrNil())

nullStatus := omitnull.Val[string]{}
nullStatus.Null()
Is(v.OmitNullString(nullStatus).EmptyOrNil())

func (*ValidatorOmitNullString[T]) EqualTo

func (validator *ValidatorOmitNullString[T]) EqualTo(value T, template ...string) *ValidatorOmitNullString[T]

Validate if an optional and nullable string value is equal to another. This function internally uses the golang `==` operator. The validation only passes if the value is set and not null and equal to the provided value. For example:

status := omitnull.Val[string]{}
status.Set("running")
Is(v.OmitNullString(status).EqualTo("running"))

func (*ValidatorOmitNullString[T]) GreaterOrEqualTo

func (validator *ValidatorOmitNullString[T]) GreaterOrEqualTo(value T, template ...string) *ValidatorOmitNullString[T]

Validate if an optional and nullable string value is greater than or equal to another. This function internally uses the golang `>=` operator. The validation only passes if the value is set and not null and greater than or equal to the provided value. For example:

section := omitnull.Val[string]{}
section.Set("bc")
Is(v.OmitNullString(section).GreaterOrEqualTo("bc"))

func (*ValidatorOmitNullString[T]) GreaterThan

func (validator *ValidatorOmitNullString[T]) GreaterThan(value T, template ...string) *ValidatorOmitNullString[T]

Validate if an optional and nullable string value is greater than another. This function internally uses the golang `>` operator. The validation only passes if the value is set and not null and greater than the provided value. For example:

section := omitnull.Val[string]{}
section.Set("bb")
Is(v.OmitNullString(section).GreaterThan("ba"))

func (*ValidatorOmitNullString[T]) InSlice

func (validator *ValidatorOmitNullString[T]) InSlice(slice []T, template ...string) *ValidatorOmitNullString[T]

Validate if an optional and nullable string is present in a string slice. The validation only passes if the value is set and not null and found in the provided slice. For example:

status := omitnull.Val[string]{}
status.Set("idle")
validStatus := []string{"idle", "paused", "stopped"}
Is(v.OmitNullString(status).InSlice(validStatus))

func (*ValidatorOmitNullString[T]) LessOrEqualTo

func (validator *ValidatorOmitNullString[T]) LessOrEqualTo(value T, template ...string) *ValidatorOmitNullString[T]

Validate if an optional and nullable string value is less than or equal to another. This function internally uses the golang `<=` operator. The validation only passes if the value is set and not null and less than or equal to the provided value. For example:

section := omitnull.Val[string]{}
section.Set("bc")
Is(v.OmitNullString(section).LessOrEqualTo("bc"))

func (*ValidatorOmitNullString[T]) LessThan

func (validator *ValidatorOmitNullString[T]) LessThan(value T, template ...string) *ValidatorOmitNullString[T]

Validate if an optional and nullable string value is less than another. This function internally uses the golang `<` operator. The validation only passes if the value is set and not null and less than the provided value. For example:

section := omitnull.Val[string]{}
section.Set("bb")
Is(v.OmitNullString(section).LessThan("bc"))

func (*ValidatorOmitNullString[T]) MatchingTo

func (validator *ValidatorOmitNullString[T]) MatchingTo(regex *regexp.Regexp, template ...string) *ValidatorOmitNullString[T]

Validate if an optional and nullable string matches a regular expression. The validation only passes if the value is set and not null and matches the provided regex. For example:

status := omitnull.Val[string]{}
status.Set("pre-approved")
regex, _ := regexp.Compile("pre-.+")
Is(v.OmitNullString(status).MatchingTo(regex))

func (*ValidatorOmitNullString[T]) MaxBytes

func (validator *ValidatorOmitNullString[T]) MaxBytes(length int, template ...string) *ValidatorOmitNullString[T]

Validate the maximum length (in bytes) of an optional and nullable string. The validation only passes if the value is set and not null and its byte length is less than or equal to the provided length. For example:

slug := omitnull.Val[string]{}
slug.Set("myname")
Is(v.OmitNullString(slug).MaxBytes(6))

For character count, use `MaxLength` instead.

func (*ValidatorOmitNullString[T]) MaxLength

func (validator *ValidatorOmitNullString[T]) MaxLength(length int, template ...string) *ValidatorOmitNullString[T]

Validate the maximum length (in runes/characters) of an optional and nullable string. The validation only passes if the value is set and not null and its rune length is less than or equal to the provided length. For example:

word := omitnull.Val[string]{}
word.Set("虎視眈々") // 4 runes, len(word) = 12 bytes
Is(v.OmitNullString(word).MaxLength(4))

func (*ValidatorOmitNullString[T]) MinBytes

func (validator *ValidatorOmitNullString[T]) MinBytes(length int, template ...string) *ValidatorOmitNullString[T]

Validate the minimum length (in bytes) of an optional and nullable string. The validation only passes if the value is set and not null and its byte length is greater than or equal to the provided length. For example:

slug := omitnull.Val[string]{}
slug.Set("myname")
Is(v.OmitNullString(slug).MinBytes(6))

For character count, use `MinLength` instead.

func (*ValidatorOmitNullString[T]) MinLength

func (validator *ValidatorOmitNullString[T]) MinLength(length int, template ...string) *ValidatorOmitNullString[T]

Validate the minimum length (in runes/characters) of an optional and nullable string. The validation only passes if the value is set and not null and its rune length is greater than or equal to the provided length. For example:

word := omitnull.Val[string]{}
word.Set("虎視眈々") // 4 runes, len(word) = 12 bytes
Is(v.OmitNullString(word).MinLength(4))

func (*ValidatorOmitNullString[T]) Nil

func (validator *ValidatorOmitNullString[T]) Nil(template ...string) *ValidatorOmitNullString[T]

Validate if an optional and nullable string value is null. The validation only passes if the value is null.

For example:

nullStatus := omitnull.Val[string]{}
nullStatus.Null()
Is(v.OmitNullString(nullStatus).Nil())

func (*ValidatorOmitNullString[T]) Not

func (validator *ValidatorOmitNullString[T]) Not() *ValidatorOmitNullString[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with the Empty() function
status := omitnull.Val[string]{}
status.Set("")
Is(v.OmitNullString(status).Not().Empty()).Valid()

func (*ValidatorOmitNullString[T]) OfByteLength

func (validator *ValidatorOmitNullString[T]) OfByteLength(length int, template ...string) *ValidatorOmitNullString[T]

Validate the length (in bytes) of an optional and nullable string. The validation only passes if the value is set and not null and its byte length equals the provided length. For example:

slug := omitnull.Val[string]{}
slug.Set("myname")
Is(v.OmitNullString(slug).OfByteLength(6))

For character count, use `OfLength` instead.

func (*ValidatorOmitNullString[T]) OfByteLengthBetween

func (validator *ValidatorOmitNullString[T]) OfByteLengthBetween(min int, max int, template ...string) *ValidatorOmitNullString[T]

Validate if the length (in bytes) of an optional and nullable string is within a range (inclusive). The validation only passes if the value is set and not null and its byte length is within the specified range. For example:

slug := omitnull.Val[string]{}
slug.Set("myname")
Is(v.OmitNullString(slug).OfByteLengthBetween(2, 6))

For character count, use `OfLengthBetween` instead.

func (*ValidatorOmitNullString[T]) OfLength

func (validator *ValidatorOmitNullString[T]) OfLength(length int, template ...string) *ValidatorOmitNullString[T]

Validate the length (in runes/characters) of an optional and nullable string. The validation only passes if the value is set and not null and its rune length equals the provided length. For example:

word := omitnull.Val[string]{}
word.Set("虎視眈々") // 4 runes, len(word) = 12 bytes
Is(v.OmitNullString(word).OfLength(4))

func (*ValidatorOmitNullString[T]) OfLengthBetween

func (validator *ValidatorOmitNullString[T]) OfLengthBetween(min int, max int, template ...string) *ValidatorOmitNullString[T]

Validate if the length (in runes/characters) of an optional and nullable string is within a range (inclusive). The validation only passes if the value is set and not null and its rune length is within the specified range. For example:

word := omitnull.Val[string]{}
word.Set("虎視眈々") // 4 runes, len(word) = 12 bytes
Is(v.OmitNullString(word).OfLengthBetween(2, 4))

func (*ValidatorOmitNullString[T]) Or

func (validator *ValidatorOmitNullString[T]) Or() *ValidatorOmitNullString[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the string is equal to "test".
input := omitnull.Val[string]{}
input.Set("test")
isValid := v.Is(v.OmitNullString(input).MinLength(5).Or().EqualTo("test")).Valid()

func (*ValidatorOmitNullString[T]) Passing

func (validator *ValidatorOmitNullString[T]) Passing(function func(v omitnull.Val[T]) bool, template ...string) *ValidatorOmitNullString[T]

Validate if an optional and nullable string value passes a custom function. The validation only passes if the value is set and not null and the custom function returns true. For example:

status := omitnull.Val[string]{}
status.Set("")
Is(v.OmitNullString(status).Passing((v string) bool {
	return v == getNewStatus()
})

func (*ValidatorOmitNullString[T]) Set

func (validator *ValidatorOmitNullString[T]) Set(template ...string) *ValidatorOmitNullString[T]

Validate if an optional and nullable string value is set (not unset). The validation only passes if the value is set (either has a value or is null, but not unset). For example:

status := omitnull.Val[string]{}
status.Set("active")
Is(v.OmitNullString(status).Set())

nullStatus := omitnull.Val[string]{}
nullStatus.Null()
Is(v.OmitNullString(nullStatus).Set())

type ValidatorOmitNullTime

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

The ValidatorOmitNullTime provides functions for setting validation rules for optional and nullable time.Time value types from the Opt library (omitnull.Val[time.Time]). These validators properly handle the optional and nullable nature of omitnull.Val[T] types, only validating when a value is set and not null.

func OmitNullTime

func OmitNullTime(value omitnull.Val[time.Time], nameAndTitle ...string) *ValidatorOmitNullTime

Receives an optional and nullable time.Time value (omitnull.Val[time.Time]) to validate.

The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `start_time` will be humanized as `Start Time`

func (*ValidatorOmitNullTime) After

func (validator *ValidatorOmitNullTime) After(value time.Time, template ...string) *ValidatorOmitNullTime

Validate if an optional and nullable time value is after a specified time. The validation only passes if the value is set and not null and after the provided value.

For example:

startTime := omitnull.Val[time.Time]{}
startTime.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
endTime := time.Date(2023, 1, 1, 1, 0, 0, 0, time.UTC)
Is(v.OmitNullTime(endTime).After(startTime)).Valid()

func (*ValidatorOmitNullTime) AfterOrEqualTo

func (validator *ValidatorOmitNullTime) AfterOrEqualTo(value time.Time, template ...string) *ValidatorOmitNullTime

Validate if an optional and nullable time value is either after or equal to a specified time. The validation only passes if the value is set and not null and after or equal to the provided value.

For example:

timeA := omitnull.Val[time.Time]{}
timeA.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
timeB := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
Is(v.OmitNullTime(timeA).AfterOrEqualTo(timeB)).Valid()

func (*ValidatorOmitNullTime) Before

func (validator *ValidatorOmitNullTime) Before(value time.Time, template ...string) *ValidatorOmitNullTime

Validate if an optional and nullable time value is before a specified time. The validation only passes if the value is set and not null and before the provided value.

For example:

startTime := omitnull.Val[time.Time]{}
startTime.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
endTime := time.Date(2023, 1, 1, 1, 0, 0, 0, time.UTC)
Is(v.OmitNullTime(startTime).Before(endTime)).Valid()

func (*ValidatorOmitNullTime) BeforeOrEqualTo

func (validator *ValidatorOmitNullTime) BeforeOrEqualTo(value time.Time, template ...string) *ValidatorOmitNullTime

Validate if an optional and nullable time value is either before or equal to a specified time. The validation only passes if the value is set and not null and before or equal to the provided value.

For example:

timeA := omitnull.Val[time.Time]{}
timeA.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
timeB := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
Is(v.OmitNullTime(timeA).BeforeOrEqualTo(timeB)).Valid()

func (*ValidatorOmitNullTime) Between

func (validator *ValidatorOmitNullTime) Between(min time.Time, max time.Time, template ...string) *ValidatorOmitNullTime

Validate if an optional and nullable time value falls within a given time range, inclusive. The validation only passes if the value is set and not null and within the specified range.

For example:

minTime := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
maxTime := time.Date(2023, 1, 1, 12, 0, 0, 0, time.UTC)
checkTime := omitnull.Val[time.Time]{}
checkTime.Set(time.Date(2023, 1, 1, 6, 0, 0, 0, time.UTC))
Is(v.OmitNullTime(checkTime).Between(minTime, maxTime)).Valid()

func (*ValidatorOmitNullTime) Context

func (validator *ValidatorOmitNullTime) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitNullTime) EqualTo

func (validator *ValidatorOmitNullTime) EqualTo(value time.Time, template ...string) *ValidatorOmitNullTime

Validate if an optional and nullable time value is equal to another. The validation only passes if the value is set and not null and equal to the provided value.

For example:

timeA := omitnull.Val[time.Time]{}
timeA.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
timeB := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
Is(v.OmitNullTime(timeA).EqualTo(timeB)).Valid()

func (*ValidatorOmitNullTime) InSlice

func (validator *ValidatorOmitNullTime) InSlice(slice []time.Time, template ...string) *ValidatorOmitNullTime

Validate if an optional and nullable time value is found within a provided slice of time values. The validation only passes if the value is set and not null and found in the provided slice.

For example:

timeA := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
timeB := time.Date(2023, 1, 1, 1, 0, 0, 0, time.UTC)
timeSlice := []time.Time{timeA, timeB}
checkTime := omitnull.Val[time.Time]{}
checkTime.Set(time.Date(2023, 1, 1, 1, 0, 0, 0, time.UTC))
Is(v.OmitNullTime(checkTime).InSlice(timeSlice)).Valid()

func (*ValidatorOmitNullTime) Nil

func (validator *ValidatorOmitNullTime) Nil(template ...string) *ValidatorOmitNullTime

Validate if an optional and nullable time value is null. The validation only passes if the value is null.

For example:

nullTime := omitnull.Val[time.Time]{}
nullTime.Null()
Is(v.OmitNullTime(nullTime).Nil())

func (*ValidatorOmitNullTime) Not

func (validator *ValidatorOmitNullTime) Not() *ValidatorOmitNullTime

Invert the logical value associated with the next validator function. For example:

// It will return false because `Not()` inverts the boolean value associated with the Zero() function
startTime := omitnull.Val[time.Time]{}
startTime.Set(time.Now())
Is(v.OmitNullTime(startTime).Not().Zero()).Valid()

func (*ValidatorOmitNullTime) Or

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the time is before or equal to time.Now().
t := omitnull.Val[time.Time]{}
t.Set(time.Now())
isValid := v.Is(v.OmitNullTime(t).Zero().Or().BeforeOrEqualTo(time.Now())).Valid()

func (*ValidatorOmitNullTime) Passing

func (validator *ValidatorOmitNullTime) Passing(function func(v omitnull.Val[time.Time]) bool, template ...string) *ValidatorOmitNullTime

Validate if an optional and nullable time value passes a custom function. The validation only passes if the value is set and not null and the custom function returns true.

For example:

checkTime := omitnull.Val[time.Time]{}
checkTime.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
Is(v.OmitNullTime(checkTime).Passing(func(t time.Time) bool {
    return t.Year() == 2023
})).Valid()

func (*ValidatorOmitNullTime) Set

func (validator *ValidatorOmitNullTime) Set(template ...string) *ValidatorOmitNullTime

Validate if an optional and nullable time value is set. The validation only passes if the value is set (regardless of whether it's null or not).

For example:

startTime := omitnull.Val[time.Time]{}
startTime.Set(time.Now())
Is(v.OmitNullTime(startTime).Set())

nullTime := omitnull.Val[time.Time]{}
nullTime.Null()
Is(v.OmitNullTime(nullTime).Set())

func (*ValidatorOmitNullTime) Zero

func (validator *ValidatorOmitNullTime) Zero(template ...string) *ValidatorOmitNullTime

Validate if an optional and nullable time value is a zero time. The validation only passes if the value is set and not null and is a zero time.

For example:

zeroTime := omitnull.Val[time.Time]{}
zeroTime.Set(time.Time{})
Is(v.OmitNullTime(zeroTime).Zero()).Valid()

func (*ValidatorOmitNullTime) ZeroOrNil

func (validator *ValidatorOmitNullTime) ZeroOrNil(template ...string) *ValidatorOmitNullTime

Validate if an optional and nullable time value is zero or null. The validation only passes if the value is null or (set and not null and equal to zero).

For example:

zeroTime := omitnull.Val[time.Time]{}
zeroTime.Set(time.Time{})
Is(v.OmitNullTime(zeroTime).ZeroOrNil())

nullTime := omitnull.Val[time.Time]{}
nullTime.Null()
Is(v.OmitNullTime(nullTime).ZeroOrNil())

type ValidatorOmitNullTyped

type ValidatorOmitNullTyped[T any] struct {
	// contains filtered or unexported fields
}

The ValidatorOmitNullTyped provides functions for setting validation rules for optional and nullable value types from the Opt library (omitnull.Val[T]), or a custom type. T can be any Go type (pointer, struct, slice, map, etc.). These validators properly handle the optional and nullable nature of omitnull.Val[T] types, only validating when a value is set and not null.

func OmitNullTyped

func OmitNullTyped[T any](value omitnull.Val[T], nameAndTitle ...string) *ValidatorOmitNullTyped[T]

Receives an optional and nullable value (omitnull.Val[T]) to validate.

The value can be any Go type (pointer, struct, slice, map, etc.), wrapped in omitnull.Val. The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A value_%N pattern is used as a name in the error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name phone_number will be humanized as Phone Number.

Example:

user := omitnull.Val[User]{}
user.Set(User{Name: "John"})
v.Is(v.OmitNullTyped(user).Not().Nil())

func (*ValidatorOmitNullTyped[T]) Context

func (validator *ValidatorOmitNullTyped[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitNullTyped[T]) EqualTo

func (validator *ValidatorOmitNullTyped[T]) EqualTo(value T, template ...string) *ValidatorOmitNullTyped[T]

Validate if an optional and nullable value is equal to another. This function uses reflection to compare values, which works for all types including incomparable types. The validation only passes if the value is set and not null and equal to the provided value. For example:

status := omitnull.Val[string]{}
status.Set("running")
Is(v.OmitNullTyped(status).EqualTo("running"))

func (*ValidatorOmitNullTyped[T]) Nil

func (validator *ValidatorOmitNullTyped[T]) Nil(template ...string) *ValidatorOmitNullTyped[T]

Validate if an optional and nullable value is nil. The validation passes if: - The omitnull.Val itself is null (using Null()), OR - The value inside is nil (for nil-able types like pointers, slices, maps, etc.)

For example:

nullVal := omitnull.Val[*string]{}
nullVal.Null()
v.Is(v.OmitNullTyped(nullVal).Nil())

var s *string
val := omitnull.Val[*string]{}
val.Set(s)
v.Is(v.OmitNullTyped(val).Nil())

func (*ValidatorOmitNullTyped[T]) Not

func (validator *ValidatorOmitNullTyped[T]) Not() *ValidatorOmitNullTyped[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with EqualTo()
val := omitnull.Val[string]{}
val.Set("a")
v.Is(v.OmitNullTyped(val).Not().EqualTo("a")).Valid()

func (*ValidatorOmitNullTyped[T]) Or

func (validator *ValidatorOmitNullTyped[T]) Or() *ValidatorOmitNullTyped[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the value is equal to "test".
input := omitnull.Val[string]{}
input.Set("test")
isValid := v.Is(v.OmitNullTyped(input).Passing(func(s string) bool { return len(s) >= 5 }).Or().EqualTo("test")).Valid()

func (*ValidatorOmitNullTyped[T]) Passing

func (validator *ValidatorOmitNullTyped[T]) Passing(function func(v omitnull.Val[T]) bool, template ...string) *ValidatorOmitNullTyped[T]

Validate if an optional and nullable value passes a custom function. The function receives a typed T value, enabling compile-time type safety. The validation only passes if the value is set and not null and the function returns true.

For example:

type Status string
status := omitnull.Val[Status]{}
status.Set(Status("running"))
isValid := v.Is(
  v.OmitNullTyped(status).Passing(func(s Status) bool {
    return s == "running" || s == "paused"
  }),
).Valid()

func (*ValidatorOmitNullTyped[T]) Set

func (validator *ValidatorOmitNullTyped[T]) Set(template ...string) *ValidatorOmitNullTyped[T]

Validate if an optional and nullable value is set (not unset). The validation passes if the value is set, regardless of whether it's null or has a value.

For example:

user := omitnull.Val[User]{}
user.Set(User{Name: "John"})
Is(v.OmitNullTyped(user).Set())

nullUser := omitnull.Val[User]{}
nullUser.Null()
Is(v.OmitNullTyped(nullUser).Set())

type ValidatorOmitNullUint

type ValidatorOmitNullUint[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64] struct {
	// contains filtered or unexported fields
}

The ValidatorOmitNullUint provides functions for setting validation rules for optional and nullable uint value types from the Opt library (omitnull.Val[T]), or a custom type based on a uint, uint8, uint16, uint32, or uint64. These validators properly handle the optional and nullable nature of omitnull.Val[T] types, only validating when a value is set and not null.

func OmitNullByte

func OmitNullByte[T ~byte](value omitnull.Val[T], nameAndTitle ...string) *ValidatorOmitNullUint[T]

Receives an optional and nullable byte value (omitnull.Val[T]) to validate.

The value can also be a custom byte type such as type Age byte, wrapped in omitnull.Val. The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitNullUint

func OmitNullUint[T ~uint](value omitnull.Val[T], nameAndTitle ...string) *ValidatorOmitNullUint[T]

Receives an optional and nullable uint value (omitnull.Val[T]) to validate.

The value can also be a custom uint type such as type Age uint, wrapped in omitnull.Val. The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitNullUint8

func OmitNullUint8[T ~uint8](value omitnull.Val[T], nameAndTitle ...string) *ValidatorOmitNullUint[T]

Receives an optional and nullable uint8 value (omitnull.Val[T]) to validate.

The value can also be a custom uint8 type such as type Age uint8, wrapped in omitnull.Val. The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitNullUint16

func OmitNullUint16[T ~uint16](value omitnull.Val[T], nameAndTitle ...string) *ValidatorOmitNullUint[T]

Receives an optional and nullable uint16 value (omitnull.Val[T]) to validate.

The value can also be a custom uint16 type such as type Age uint16, wrapped in omitnull.Val. The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitNullUint32

func OmitNullUint32[T ~uint32](value omitnull.Val[T], nameAndTitle ...string) *ValidatorOmitNullUint[T]

Receives an optional and nullable uint32 value (omitnull.Val[T]) to validate.

The value can also be a custom uint32 type such as type Age uint32, wrapped in omitnull.Val. The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitNullUint64

func OmitNullUint64[T ~uint64](value omitnull.Val[T], nameAndTitle ...string) *ValidatorOmitNullUint[T]

Receives an optional and nullable uint64 value (omitnull.Val[T]) to validate.

The value can also be a custom uint64 type such as type Age uint64, wrapped in omitnull.Val. The validator will only perform validation checks when the value is set and not null.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func (*ValidatorOmitNullUint[T]) Between

func (validator *ValidatorOmitNullUint[T]) Between(min T, max T, template ...string) *ValidatorOmitNullUint[T]

Validate if an optional and nullable number is within a range (inclusive). The validation only passes if the value is set and not null and within the specified range. For example:

quantity := omitnull.Val[uint]{}
quantity.Set(3)
Is(v.OmitNullUint(quantity).Between(2,6))

func (*ValidatorOmitNullUint[T]) Context

func (validator *ValidatorOmitNullUint[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitNullUint[T]) EqualTo

func (validator *ValidatorOmitNullUint[T]) EqualTo(value T, template ...string) *ValidatorOmitNullUint[T]

Validate if an optional and nullable numeric value is equal to another. This function internally uses the golang `==` operator. The validation only passes if the value is set and not null and equal to the provided value. For example:

quantity := omitnull.Val[uint]{}
quantity.Set(2)
Is(v.OmitNullUint(quantity).EqualTo(2))

func (*ValidatorOmitNullUint[T]) GreaterOrEqualTo

func (validator *ValidatorOmitNullUint[T]) GreaterOrEqualTo(value T, template ...string) *ValidatorOmitNullUint[T]

Validate if an optional and nullable numeric value is greater than or equal to another. This function internally uses the golang `>=` operator. The validation only passes if the value is set and not null and greater than or equal to the provided value. For example:

quantity := omitnull.Val[uint]{}
quantity.Set(3)
Is(v.OmitNullUint(quantity).GreaterOrEqualTo(3))

func (*ValidatorOmitNullUint[T]) GreaterThan

func (validator *ValidatorOmitNullUint[T]) GreaterThan(value T, template ...string) *ValidatorOmitNullUint[T]

Validate if an optional and nullable numeric value is greater than another. This function internally uses the golang `>` operator. The validation only passes if the value is set and not null and greater than the provided value. For example:

quantity := omitnull.Val[uint]{}
quantity.Set(3)
Is(v.OmitNullUint(quantity).GreaterThan(2))

func (*ValidatorOmitNullUint[T]) InSlice

func (validator *ValidatorOmitNullUint[T]) InSlice(slice []T, template ...string) *ValidatorOmitNullUint[T]

Validate if an optional and nullable number is present in a numeric slice. The validation only passes if the value is set and not null and found in the provided slice. For example:

quantity := omitnull.Val[uint]{}
quantity.Set(3)
validQuantities := []uint{1,3,5}
Is(v.OmitNullUint(quantity).InSlice(validQuantities))

func (*ValidatorOmitNullUint[T]) LessOrEqualTo

func (validator *ValidatorOmitNullUint[T]) LessOrEqualTo(value T, template ...string) *ValidatorOmitNullUint[T]

Validate if an optional and nullable numeric value is less than or equal to another. This function internally uses the golang `<=` operator. The validation only passes if the value is set and not null and less than or equal to the provided value. For example:

quantity := omitnull.Val[uint]{}
quantity.Set(2)
Is(v.OmitNullUint(quantity).LessOrEqualTo(2))

func (*ValidatorOmitNullUint[T]) LessThan

func (validator *ValidatorOmitNullUint[T]) LessThan(value T, template ...string) *ValidatorOmitNullUint[T]

Validate if an optional and nullable numeric value is less than another. This function internally uses the golang `<` operator. The validation only passes if the value is set and not null and less than the provided value. For example:

quantity := omitnull.Val[uint]{}
quantity.Set(2)
Is(v.OmitNullUint(quantity).LessThan(3))

func (*ValidatorOmitNullUint[T]) Nil

func (validator *ValidatorOmitNullUint[T]) Nil(template ...string) *ValidatorOmitNullUint[T]

Validate if an optional and nullable numeric value is null. The validation only passes if the value is null.

For example:

nullQuantity := omitnull.Val[uint]{}
nullQuantity.Null()
Is(v.OmitNullUint(nullQuantity).Nil())

func (*ValidatorOmitNullUint[T]) Not

func (validator *ValidatorOmitNullUint[T]) Not() *ValidatorOmitNullUint[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with the Zero() function
quantity := omitnull.Val[uint]{}
quantity.Set(0)
Is(v.OmitNullUint(quantity).Not().Zero()).Valid()

func (*ValidatorOmitNullUint[T]) Or

func (validator *ValidatorOmitNullUint[T]) Or() *ValidatorOmitNullUint[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the input is Zero.
input := omitnull.Val[uint]{}
input.Set(0)
isValid := v.Is(v.OmitNullUint(input).GreaterThan(5).Or().Zero()).Valid()

func (*ValidatorOmitNullUint[T]) Passing

func (validator *ValidatorOmitNullUint[T]) Passing(function func(v omitnull.Val[T]) bool, template ...string) *ValidatorOmitNullUint[T]

Validate if an optional and nullable numeric value passes a custom function. The validation only passes if the value is set and not null and the custom function returns true. For example:

quantity := omitnull.Val[uint]{}
quantity.Set(2)
Is(v.OmitNullUint(quantity).Passing((v uint) bool {
	return v == getAllowedQuantity()
})

func (*ValidatorOmitNullUint[T]) Positive

func (validator *ValidatorOmitNullUint[T]) Positive(template ...string) *ValidatorOmitNullUint[T]

Validate if an optional and nullable numeric value is positive (greater than zero). The validation only passes if the value is set and not null and greater than zero.

For example:

quantity := omitnull.Val[uint]{}
quantity.Set(5)
Is(v.OmitNullUint(quantity).Positive())

func (*ValidatorOmitNullUint[T]) Set

func (validator *ValidatorOmitNullUint[T]) Set(template ...string) *ValidatorOmitNullUint[T]

Validate if an optional and nullable numeric value is set (not unset). The validation only passes if the value is set (either has a value or is null, but not unset). For example:

quantity := omitnull.Val[uint]{}
quantity.Set(5)
Is(v.OmitNullUint(quantity).Set())

nullQuantity := omitnull.Val[uint]{}
nullQuantity.Null()
Is(v.OmitNullUint(nullQuantity).Set())

func (*ValidatorOmitNullUint[T]) Zero

func (validator *ValidatorOmitNullUint[T]) Zero(template ...string) *ValidatorOmitNullUint[T]

Validate if an optional and nullable numeric value is zero. The validation only passes if the value is set and not null and equal to zero.

For example:

quantity := omitnull.Val[uint]{}
quantity.Set(0)
Is(v.OmitNullUint(quantity).Zero())

func (*ValidatorOmitNullUint[T]) ZeroOrNil

func (validator *ValidatorOmitNullUint[T]) ZeroOrNil(template ...string) *ValidatorOmitNullUint[T]

Validate if an optional and nullable numeric value is zero or null. The validation passes if the value is null or (set and not null and equal to zero).

For example:

quantity := omitnull.Val[uint]{}
quantity.Set(0)
Is(v.OmitNullUint(quantity).ZeroOrNil())

nullQuantity := omitnull.Val[uint]{}
nullQuantity.Null()
Is(v.OmitNullUint(nullQuantity).ZeroOrNil())

type ValidatorOmitNumber

type ValidatorOmitNumber[T TypeNumber] struct {
	// contains filtered or unexported fields
}

The ValidatorOmitNumber provides functions for setting validation rules for optional numeric value types from the Opt library (omit.Val[T]), or a custom type based on a TypeNumber. These validators properly handle the optional nature of omit.Val[T] types, only validating when a value is set.

func OmitNumber

func OmitNumber[T TypeNumber](value omit.Val[T], nameAndTitle ...string) *ValidatorOmitNumber[T]

Receives an optional numeric value (omit.Val[T]) to validate.

The value can be any golang numeric type (int64, int32, float32, uint, etc.) or a custom numeric type such as `type Level int32;`, wrapped in omit.Val. The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func (*ValidatorOmitNumber[T]) Between

func (validator *ValidatorOmitNumber[T]) Between(min T, max T, template ...string) *ValidatorOmitNumber[T]

Validate if an optional number is within a range (inclusive). The validation only passes if the value is set and within the specified range. For example:

quantity := omit.Val[int]{}
quantity.Set(3)
Is(v.OmitNumber(quantity).Between(2,6))

func (*ValidatorOmitNumber[T]) Context

func (validator *ValidatorOmitNumber[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitNumber[T]) EqualTo

func (validator *ValidatorOmitNumber[T]) EqualTo(value T, template ...string) *ValidatorOmitNumber[T]

Validate if an optional numeric value is equal to another. This function internally uses the golang `==` operator. The validation only passes if the value is set and equal to the provided value. For example:

quantity := omit.Val[int]{}
quantity.Set(2)
Is(v.OmitNumber(quantity).EqualTo(2))

func (*ValidatorOmitNumber[T]) GreaterOrEqualTo

func (validator *ValidatorOmitNumber[T]) GreaterOrEqualTo(value T, template ...string) *ValidatorOmitNumber[T]

Validate if an optional numeric value is greater than or equal to another. This function internally uses the golang `>=` operator. The validation only passes if the value is set and greater than or equal to the provided value. For example:

quantity := omit.Val[int]{}
quantity.Set(3)
Is(v.OmitNumber(quantity).GreaterOrEqualTo(3))

func (*ValidatorOmitNumber[T]) GreaterThan

func (validator *ValidatorOmitNumber[T]) GreaterThan(value T, template ...string) *ValidatorOmitNumber[T]

Validate if an optional numeric value is greater than another. This function internally uses the golang `>` operator. The validation only passes if the value is set and greater than the provided value. For example:

quantity := omit.Val[int]{}
quantity.Set(3)
Is(v.OmitNumber(quantity).GreaterThan(2))

func (*ValidatorOmitNumber[T]) InSlice

func (validator *ValidatorOmitNumber[T]) InSlice(slice []T, template ...string) *ValidatorOmitNumber[T]

Validate if an optional number is present in a numeric slice. The validation only passes if the value is set and found in the provided slice. For example:

quantity := omit.Val[int]{}
quantity.Set(3)
validQuantities := []int{1,3,5}
Is(v.OmitNumber(quantity).InSlice(validQuantities))

func (*ValidatorOmitNumber[T]) LessOrEqualTo

func (validator *ValidatorOmitNumber[T]) LessOrEqualTo(value T, template ...string) *ValidatorOmitNumber[T]

Validate if an optional numeric value is less than or equal to another. This function internally uses the golang `<=` operator. The validation only passes if the value is set and less than or equal to the provided value. For example:

quantity := omit.Val[int]{}
quantity.Set(2)
Is(v.OmitNumber(quantity).LessOrEqualTo(2))

func (*ValidatorOmitNumber[T]) LessThan

func (validator *ValidatorOmitNumber[T]) LessThan(value T, template ...string) *ValidatorOmitNumber[T]

Validate if an optional numeric value is less than another. This function internally uses the golang `<` operator. The validation only passes if the value is set and less than the provided value. For example:

quantity := omit.Val[int]{}
quantity.Set(2)
Is(v.OmitNumber(quantity).LessThan(3))

func (*ValidatorOmitNumber[T]) Not

func (validator *ValidatorOmitNumber[T]) Not() *ValidatorOmitNumber[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with the Zero() function
quantity := omit.Val[int]{}
quantity.Set(0)
Is(v.OmitNumber(quantity).Not().Zero()).Valid()

func (*ValidatorOmitNumber[T]) Or

func (validator *ValidatorOmitNumber[T]) Or() *ValidatorOmitNumber[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the input is Zero.
input := omit.Val[int]{}
input.Set(0)
isValid := v.Is(v.OmitNumber(input).GreaterThan(5).Or().Zero()).Valid()

func (*ValidatorOmitNumber[T]) Passing

func (validator *ValidatorOmitNumber[T]) Passing(function func(v omit.Val[T]) bool, template ...string) *ValidatorOmitNumber[T]

Validate if an optional numeric value passes a custom function. The validation only passes if the value is set and the custom function returns true. For example:

quantity := omit.Val[int]{}
quantity.Set(2)
Is(v.OmitNumber(quantity).Passing((v int) bool {
	return v == getAllowedQuantity()
})

func (*ValidatorOmitNumber[T]) Set

func (validator *ValidatorOmitNumber[T]) Set(template ...string) *ValidatorOmitNumber[T]

Validate if an optional numeric value is set. The validation only passes if the value is set. For example:

quantity := omit.Val[int]{}
quantity.Set(5)
Is(v.OmitNumber(quantity).Set())

func (*ValidatorOmitNumber[T]) Zero

func (validator *ValidatorOmitNumber[T]) Zero(template ...string) *ValidatorOmitNumber[T]

Validate if an optional numeric value is zero. The validation only passes if the value is set and equal to zero.

For example:

quantity := omit.Val[int]{}
quantity.Set(0)
Is(v.OmitNumber(quantity).Zero())

type ValidatorOmitString

type ValidatorOmitString[T ~string] struct {
	// contains filtered or unexported fields
}

The ValidatorOmitString provides functions for setting validation rules for optional string value types from the Opt library (omit.Val[T]), or a custom type based on a string. These validators properly handle the optional nature of omit.Val[T] types, only validating when a value is set.

func OmitString

func OmitString[T ~string](value omit.Val[T], nameAndTitle ...string) *ValidatorOmitString[T]

Receives an optional string value (omit.Val[T]) to validate.

The value can also be a custom string type such as type Status string, wrapped in omit.Val. The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func (*ValidatorOmitString[T]) Between

func (validator *ValidatorOmitString[T]) Between(min T, max T, template ...string) *ValidatorOmitString[T]

Validate if the value of an optional string is within a range (inclusive). The validation only passes if the value is set and within the specified range. For example:

slug := omit.Val[string]{}
slug.Set("ab")
Is(v.OmitString(slug).Between("ab", "ac"))

func (*ValidatorOmitString[T]) Blank

func (validator *ValidatorOmitString[T]) Blank(template ...string) *ValidatorOmitString[T]

Validate if an optional string value is blank. Blank will be true if the length of the string is zero or if the string only has spaces. The validation only passes if the value is set and blank. For example:

status := omit.Val[string]{}
status.Set("")
Is(v.OmitString(status).Blank()) // Will be true

status2 := omit.Val[string]{}
status2.Set(" ")
Is(v.OmitString(status2).Blank()) // Will be true

func (*ValidatorOmitString[T]) Context

func (validator *ValidatorOmitString[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitString[T]) Empty

func (validator *ValidatorOmitString[T]) Empty(template ...string) *ValidatorOmitString[T]

Validate if an optional string value is empty. Return false if the length of the string is greater than zero, even if the string has only spaces. The validation only passes if the value is set and empty.

For checking if the string has only spaces, use the function `Blank()` instead. For example:

status := omit.Val[string]{}
status.Set("")
Is(v.OmitString(status).Empty()) // Will be true

func (*ValidatorOmitString[T]) EqualTo

func (validator *ValidatorOmitString[T]) EqualTo(value T, template ...string) *ValidatorOmitString[T]

Validate if an optional string value is equal to another. This function internally uses the golang `==` operator. The validation only passes if the value is set and equal to the provided value. For example:

status := omit.Val[string]{}
status.Set("running")
Is(v.OmitString(status).EqualTo("running"))

func (*ValidatorOmitString[T]) GreaterOrEqualTo

func (validator *ValidatorOmitString[T]) GreaterOrEqualTo(value T, template ...string) *ValidatorOmitString[T]

Validate if an optional string value is greater than or equal to another. This function internally uses the golang `>=` operator. The validation only passes if the value is set and greater than or equal to the provided value. For example:

section := omit.Val[string]{}
section.Set("bc")
Is(v.OmitString(section).GreaterOrEqualTo("bc"))

func (*ValidatorOmitString[T]) GreaterThan

func (validator *ValidatorOmitString[T]) GreaterThan(value T, template ...string) *ValidatorOmitString[T]

Validate if an optional string value is greater than another. This function internally uses the golang `>` operator. The validation only passes if the value is set and greater than the provided value. For example:

section := omit.Val[string]{}
section.Set("bb")
Is(v.OmitString(section).GreaterThan("ba"))

func (*ValidatorOmitString[T]) InSlice

func (validator *ValidatorOmitString[T]) InSlice(slice []T, template ...string) *ValidatorOmitString[T]

Validate if an optional string is present in a string slice. The validation only passes if the value is set and found in the provided slice. For example:

status := omit.Val[string]{}
status.Set("idle")
validStatus := []string{"idle", "paused", "stopped"}
Is(v.OmitString(status).InSlice(validStatus))

func (*ValidatorOmitString[T]) LessOrEqualTo

func (validator *ValidatorOmitString[T]) LessOrEqualTo(value T, template ...string) *ValidatorOmitString[T]

Validate if an optional string value is less than or equal to another. This function internally uses the golang `<=` operator. The validation only passes if the value is set and less than or equal to the provided value. For example:

section := omit.Val[string]{}
section.Set("bc")
Is(v.OmitString(section).LessOrEqualTo("bc"))

func (*ValidatorOmitString[T]) LessThan

func (validator *ValidatorOmitString[T]) LessThan(value T, template ...string) *ValidatorOmitString[T]

Validate if an optional string value is less than another. This function internally uses the golang `<` operator. The validation only passes if the value is set and less than the provided value. For example:

section := omit.Val[string]{}
section.Set("bb")
Is(v.OmitString(section).LessThan("bc"))

func (*ValidatorOmitString[T]) MatchingTo

func (validator *ValidatorOmitString[T]) MatchingTo(regex *regexp.Regexp, template ...string) *ValidatorOmitString[T]

Validate if an optional string matches a regular expression. The validation only passes if the value is set and matches the provided regex. For example:

status := omit.Val[string]{}
status.Set("pre-approved")
regex, _ := regexp.Compile("pre-.+")
Is(v.OmitString(status).MatchingTo(regex))

func (*ValidatorOmitString[T]) MaxBytes

func (validator *ValidatorOmitString[T]) MaxBytes(length int, template ...string) *ValidatorOmitString[T]

Validate the maximum length (in bytes) of an optional string. The validation only passes if the value is set and its byte length is less than or equal to the provided length. For example:

slug := omit.Val[string]{}
slug.Set("myname")
Is(v.OmitString(slug).MaxBytes(6))

For character count, use `MaxLength` instead.

func (*ValidatorOmitString[T]) MaxLength

func (validator *ValidatorOmitString[T]) MaxLength(length int, template ...string) *ValidatorOmitString[T]

Validate the maximum length (in runes/characters) of an optional string. The validation only passes if the value is set and its rune length is less than or equal to the provided length. For example:

word := omit.Val[string]{}
word.Set("虎視眈々") // 4 runes, len(word) = 12 bytes
Is(v.OmitString(word).MaxLength(4))

func (*ValidatorOmitString[T]) MinBytes

func (validator *ValidatorOmitString[T]) MinBytes(length int, template ...string) *ValidatorOmitString[T]

Validate the minimum length (in bytes) of an optional string. The validation only passes if the value is set and its byte length is greater than or equal to the provided length. For example:

slug := omit.Val[string]{}
slug.Set("myname")
Is(v.OmitString(slug).MinBytes(6))

For character count, use `MinLength` instead.

func (*ValidatorOmitString[T]) MinLength

func (validator *ValidatorOmitString[T]) MinLength(length int, template ...string) *ValidatorOmitString[T]

Validate the minimum length (in runes/characters) of an optional string. The validation only passes if the value is set and its rune length is greater than or equal to the provided length. For example:

word := omit.Val[string]{}
word.Set("虎視眈々") // 4 runes, len(word) = 12 bytes
Is(v.OmitString(word).MinLength(4))

func (*ValidatorOmitString[T]) Not

func (validator *ValidatorOmitString[T]) Not() *ValidatorOmitString[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with the Empty() function
status := omit.Val[string]{}
status.Set("")
Is(v.OmitString(status).Not().Empty()).Valid()

func (*ValidatorOmitString[T]) OfByteLength

func (validator *ValidatorOmitString[T]) OfByteLength(length int, template ...string) *ValidatorOmitString[T]

Validate the length (in bytes) of an optional string. The validation only passes if the value is set and its byte length equals the provided length. For example:

slug := omit.Val[string]{}
slug.Set("myname")
Is(v.OmitString(slug).OfByteLength(6))

For character count, use `OfLength` instead.

func (*ValidatorOmitString[T]) OfByteLengthBetween

func (validator *ValidatorOmitString[T]) OfByteLengthBetween(min int, max int, template ...string) *ValidatorOmitString[T]

Validate if the length (in bytes) of an optional string is within a range (inclusive). The validation only passes if the value is set and its byte length is within the specified range. For example:

slug := omit.Val[string]{}
slug.Set("myname")
Is(v.OmitString(slug).OfByteLengthBetween(2, 6))

For character count, use `OfLengthBetween` instead.

func (*ValidatorOmitString[T]) OfLength

func (validator *ValidatorOmitString[T]) OfLength(length int, template ...string) *ValidatorOmitString[T]

Validate the length (in runes/characters) of an optional string. The validation only passes if the value is set and its rune length equals the provided length. For example:

word := omit.Val[string]{}
word.Set("虎視眈々") // 4 runes, len(word) = 12 bytes
Is(v.OmitString(word).OfLength(4))

func (*ValidatorOmitString[T]) OfLengthBetween

func (validator *ValidatorOmitString[T]) OfLengthBetween(min int, max int, template ...string) *ValidatorOmitString[T]

Validate if the length (in runes/characters) of an optional string is within a range (inclusive). The validation only passes if the value is set and its rune length is within the specified range. For example:

word := omit.Val[string]{}
word.Set("虎視眈々") // 4 runes, len(word) = 12 bytes
Is(v.OmitString(word).OfLengthBetween(2, 4))

func (*ValidatorOmitString[T]) Or

func (validator *ValidatorOmitString[T]) Or() *ValidatorOmitString[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the string is equal to "test".
input := omit.Val[string]{}
input.Set("test")
isValid := v.Is(v.OmitString(input).MinLength(5).Or().EqualTo("test")).Valid()

func (*ValidatorOmitString[T]) Passing

func (validator *ValidatorOmitString[T]) Passing(function func(v omit.Val[T]) bool, template ...string) *ValidatorOmitString[T]

Validate if an optional string value passes a custom function. The validation only passes if the value is set and the custom function returns true. For example:

status := omit.Val[string]{}
status.Set("")
Is(v.OmitString(status).Passing((v string) bool {
	return v == getNewStatus()
})

func (*ValidatorOmitString[T]) Set

func (validator *ValidatorOmitString[T]) Set(template ...string) *ValidatorOmitString[T]

Validate if an optional string value is set. The validation only passes if the value is set. For example:

status := omit.Val[string]{}
status.Set("active")
Is(v.OmitString(status).Set())

type ValidatorOmitTime

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

The ValidatorOmitTime provides functions for setting validation rules for optional time.Time value types from the Opt library (omit.Val[time.Time]). These validators properly handle the optional nature of omit.Val[T] types, only validating when a value is set.

func OmitTime

func OmitTime(value omit.Val[time.Time], nameAndTitle ...string) *ValidatorOmitTime

Receives an optional time.Time value (omit.Val[time.Time]) to validate.

The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `start_time` will be humanized as `Start Time`

func (*ValidatorOmitTime) After

func (validator *ValidatorOmitTime) After(value time.Time, template ...string) *ValidatorOmitTime

Validate if an optional time value is after a specified time. The validation only passes if the value is set and after the provided value.

For example:

startTime := omit.Val[time.Time]{}
startTime.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
endTime := time.Date(2023, 1, 1, 1, 0, 0, 0, time.UTC)
Is(v.OmitTime(endTime).After(startTime)).Valid()

func (*ValidatorOmitTime) AfterOrEqualTo

func (validator *ValidatorOmitTime) AfterOrEqualTo(value time.Time, template ...string) *ValidatorOmitTime

Validate if an optional time value is either after or equal to a specified time. The validation only passes if the value is set and after or equal to the provided value.

For example:

timeA := omit.Val[time.Time]{}
timeA.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
timeB := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
Is(v.OmitTime(timeA).AfterOrEqualTo(timeB)).Valid()

func (*ValidatorOmitTime) Before

func (validator *ValidatorOmitTime) Before(value time.Time, template ...string) *ValidatorOmitTime

Validate if an optional time value is before a specified time. The validation only passes if the value is set and before the provided value.

For example:

startTime := omit.Val[time.Time]{}
startTime.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
endTime := time.Date(2023, 1, 1, 1, 0, 0, 0, time.UTC)
Is(v.OmitTime(startTime).Before(endTime)).Valid()

func (*ValidatorOmitTime) BeforeOrEqualTo

func (validator *ValidatorOmitTime) BeforeOrEqualTo(value time.Time, template ...string) *ValidatorOmitTime

Validate if an optional time value is either before or equal to a specified time. The validation only passes if the value is set and before or equal to the provided value.

For example:

timeA := omit.Val[time.Time]{}
timeA.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
timeB := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
Is(v.OmitTime(timeA).BeforeOrEqualTo(timeB)).Valid()

func (*ValidatorOmitTime) Between

func (validator *ValidatorOmitTime) Between(min time.Time, max time.Time, template ...string) *ValidatorOmitTime

Validate if an optional time value falls within a given time range, inclusive. The validation only passes if the value is set and within the specified range.

For example:

minTime := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
maxTime := time.Date(2023, 1, 1, 12, 0, 0, 0, time.UTC)
checkTime := omit.Val[time.Time]{}
checkTime.Set(time.Date(2023, 1, 1, 6, 0, 0, 0, time.UTC))
Is(v.OmitTime(checkTime).Between(minTime, maxTime)).Valid()

func (*ValidatorOmitTime) Context

func (validator *ValidatorOmitTime) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitTime) EqualTo

func (validator *ValidatorOmitTime) EqualTo(value time.Time, template ...string) *ValidatorOmitTime

Validate if an optional time value is equal to another. The validation only passes if the value is set and equal to the provided value.

For example:

timeA := omit.Val[time.Time]{}
timeA.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
timeB := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
Is(v.OmitTime(timeA).EqualTo(timeB)).Valid()

func (*ValidatorOmitTime) InSlice

func (validator *ValidatorOmitTime) InSlice(slice []time.Time, template ...string) *ValidatorOmitTime

Validate if an optional time value is found within a provided slice of time values. The validation only passes if the value is set and found in the provided slice.

For example:

timeA := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
timeB := time.Date(2023, 1, 1, 1, 0, 0, 0, time.UTC)
timeSlice := []time.Time{timeA, timeB}
checkTime := omit.Val[time.Time]{}
checkTime.Set(time.Date(2023, 1, 1, 1, 0, 0, 0, time.UTC))
Is(v.OmitTime(checkTime).InSlice(timeSlice)).Valid()

func (*ValidatorOmitTime) Not

func (validator *ValidatorOmitTime) Not() *ValidatorOmitTime

Invert the logical value associated with the next validator function. For example:

// It will return false because `Not()` inverts the boolean value associated with the Zero() function
startTime := omit.Val[time.Time]{}
startTime.Set(time.Now())
Is(v.OmitTime(startTime).Not().Zero()).Valid()

func (*ValidatorOmitTime) Or

func (validator *ValidatorOmitTime) Or() *ValidatorOmitTime

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the time is before or equal to time.Now().
t := omit.Val[time.Time]{}
t.Set(time.Now())
isValid := v.Is(v.OmitTime(t).Zero().Or().BeforeOrEqualTo(time.Now())).Valid()

func (*ValidatorOmitTime) Passing

func (validator *ValidatorOmitTime) Passing(function func(v omit.Val[time.Time]) bool, template ...string) *ValidatorOmitTime

Validate if an optional time value passes a custom function. The validation only passes if the value is set and the custom function returns true.

For example:

checkTime := omit.Val[time.Time]{}
checkTime.Set(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
Is(v.OmitTime(checkTime).Passing(func(t time.Time) bool {
    return t.Year() == 2023
})).Valid()

func (*ValidatorOmitTime) Set

func (validator *ValidatorOmitTime) Set(template ...string) *ValidatorOmitTime

Validate if an optional time value is set. The validation only passes if the value is set.

For example:

startTime := omit.Val[time.Time]{}
startTime.Set(time.Now())
Is(v.OmitTime(startTime).Set())

func (*ValidatorOmitTime) Zero

func (validator *ValidatorOmitTime) Zero(template ...string) *ValidatorOmitTime

Validate if an optional time value is a zero time. The validation only passes if the value is set and is a zero time.

For example:

zeroTime := omit.Val[time.Time]{}
zeroTime.Set(time.Time{})
Is(v.OmitTime(zeroTime).Zero()).Valid()

type ValidatorOmitTyped

type ValidatorOmitTyped[T any] struct {
	// contains filtered or unexported fields
}

The ValidatorOmitTyped provides functions for setting validation rules for optional value types from the Opt library (omit.Val[T]), or a custom type. T can be any Go type (pointer, struct, slice, map, etc.). These validators properly handle the optional nature of omit.Val[T] types, only validating when a value is set.

func OmitTyped

func OmitTyped[T any](value omit.Val[T], nameAndTitle ...string) *ValidatorOmitTyped[T]

Receives an optional value (omit.Val[T]) to validate.

The value can be any Go type (pointer, struct, slice, map, etc.), wrapped in omit.Val. The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A value_%N pattern is used as a name in the error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name phone_number will be humanized as Phone Number.

Example:

user := omit.Val[User]{}
user.Set(User{Name: "John"})
v.Is(v.OmitTyped(user).Not().Nil())

func (*ValidatorOmitTyped[T]) Context

func (validator *ValidatorOmitTyped[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitTyped[T]) EqualTo

func (validator *ValidatorOmitTyped[T]) EqualTo(value T, template ...string) *ValidatorOmitTyped[T]

Validate if an optional value is equal to another. This function uses reflection to compare values, which works for all types including incomparable types. The validation only passes if the value is set and equal to the provided value. For example:

status := omit.Val[string]{}
status.Set("running")
Is(v.OmitTyped(status).EqualTo("running"))

func (*ValidatorOmitTyped[T]) Nil

func (validator *ValidatorOmitTyped[T]) Nil(template ...string) *ValidatorOmitTyped[T]

Validate if an optional value is nil. Works for nil-able kinds: pointers, slices, maps, chans, funcs, and interfaces. For non-nil-able types, this will return false. The validation only passes if the value is set and is nil.

For example:

var s *string
val := omit.Val[*string]{}
val.Set(s)
v.Is(v.OmitTyped(val).Nil())

func (*ValidatorOmitTyped[T]) Not

func (validator *ValidatorOmitTyped[T]) Not() *ValidatorOmitTyped[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with EqualTo()
val := omit.Val[string]{}
val.Set("a")
v.Is(v.OmitTyped(val).Not().EqualTo("a")).Valid()

func (*ValidatorOmitTyped[T]) Or

func (validator *ValidatorOmitTyped[T]) Or() *ValidatorOmitTyped[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the value is equal to "test".
input := omit.Val[string]{}
input.Set("test")
isValid := v.Is(v.OmitTyped(input).Passing(func(s string) bool { return len(s) >= 5 }).Or().EqualTo("test")).Valid()

func (*ValidatorOmitTyped[T]) Passing

func (validator *ValidatorOmitTyped[T]) Passing(function func(v omit.Val[T]) bool, template ...string) *ValidatorOmitTyped[T]

Validate if an optional value passes a custom function. The function receives a typed T value, enabling compile-time type safety. The validation only passes if the value is set and the function returns true.

For example:

type Status string
status := omit.Val[Status]{}
status.Set(Status("running"))
isValid := v.Is(
  v.OmitTyped(status).Passing(func(s Status) bool {
    return s == "running" || s == "paused"
  }),
).Valid()

func (*ValidatorOmitTyped[T]) Set

func (validator *ValidatorOmitTyped[T]) Set(template ...string) *ValidatorOmitTyped[T]

Validate if an optional value is set (not unset). The validation passes if the value is set, regardless of its content.

For example:

user := omit.Val[User]{}
user.Set(User{Name: "John"})
Is(v.OmitTyped(user).Set())

type ValidatorOmitUint

type ValidatorOmitUint[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64] struct {
	// contains filtered or unexported fields
}

The ValidatorOmitUint provides functions for setting validation rules for optional uint value types from the Opt library (omit.Val[T]), or a custom type based on a uint, uint8, uint16, uint32, or uint64. These validators properly handle the optional nature of omit.Val[T] types, only validating when a value is set.

func OmitByte

func OmitByte[T ~byte](value omit.Val[T], nameAndTitle ...string) *ValidatorOmitUint[T]

Receives an optional byte value (omit.Val[T]) to validate.

The value can also be a custom byte type such as type Age byte, wrapped in omit.Val. The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitUint

func OmitUint[T ~uint](value omit.Val[T], nameAndTitle ...string) *ValidatorOmitUint[T]

Receives an optional uint value (omit.Val[T]) to validate.

The value can also be a custom uint type such as type Age uint, wrapped in omit.Val. The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitUint8

func OmitUint8[T ~uint8](value omit.Val[T], nameAndTitle ...string) *ValidatorOmitUint[T]

Receives an optional uint8 value (omit.Val[T]) to validate.

The value can also be a custom uint8 type such as type Age uint8, wrapped in omit.Val. The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitUint16

func OmitUint16[T ~uint16](value omit.Val[T], nameAndTitle ...string) *ValidatorOmitUint[T]

Receives an optional uint16 value (omit.Val[T]) to validate.

The value can also be a custom uint16 type such as type Age uint16, wrapped in omit.Val. The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitUint32

func OmitUint32[T ~uint32](value omit.Val[T], nameAndTitle ...string) *ValidatorOmitUint[T]

Receives an optional uint32 value (omit.Val[T]) to validate.

The value can also be a custom uint32 type such as type Age uint32, wrapped in omit.Val. The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func OmitUint64

func OmitUint64[T ~uint64](value omit.Val[T], nameAndTitle ...string) *ValidatorOmitUint[T]

Receives an optional uint64 value (omit.Val[T]) to validate.

The value can also be a custom uint64 type such as type Age uint64, wrapped in omit.Val. The validator will only perform validation checks when the value is set.

Optionally, the function can receive a name and title, in that order, to be displayed in the error messages. A `value_%N" pattern is used as a name in error messages if a name and title are not supplied; for example: value_0. When the name is provided but not the title, then the name is humanized to be used as the title as well; for example the name `phone_number` will be humanized as `Phone Number`

func (*ValidatorOmitUint[T]) Between

func (validator *ValidatorOmitUint[T]) Between(min T, max T, template ...string) *ValidatorOmitUint[T]

Validate if an optional number is within a range (inclusive). The validation only passes if the value is set and within the specified range. For example:

quantity := omit.Val[uint]{}
quantity.Set(3)
Is(v.OmitUint(quantity).Between(2,6))

func (*ValidatorOmitUint[T]) Context

func (validator *ValidatorOmitUint[T]) Context() *valgo.ValidatorContext

Return the context of the validator. The context is useful to create a custom validator by extending this validator.

func (*ValidatorOmitUint[T]) EqualTo

func (validator *ValidatorOmitUint[T]) EqualTo(value T, template ...string) *ValidatorOmitUint[T]

Validate if an optional numeric value is equal to another. This function internally uses the golang `==` operator. The validation only passes if the value is set and equal to the provided value. For example:

quantity := omit.Val[uint]{}
quantity.Set(2)
Is(v.OmitUint(quantity).EqualTo(2))

func (*ValidatorOmitUint[T]) GreaterOrEqualTo

func (validator *ValidatorOmitUint[T]) GreaterOrEqualTo(value T, template ...string) *ValidatorOmitUint[T]

Validate if an optional numeric value is greater than or equal to another. This function internally uses the golang `>=` operator. The validation only passes if the value is set and greater than or equal to the provided value. For example:

quantity := omit.Val[uint]{}
quantity.Set(3)
Is(v.OmitUint(quantity).GreaterOrEqualTo(3))

func (*ValidatorOmitUint[T]) GreaterThan

func (validator *ValidatorOmitUint[T]) GreaterThan(value T, template ...string) *ValidatorOmitUint[T]

Validate if an optional numeric value is greater than another. This function internally uses the golang `>` operator. The validation only passes if the value is set and greater than the provided value. For example:

quantity := omit.Val[uint]{}
quantity.Set(3)
Is(v.OmitUint(quantity).GreaterThan(2))

func (*ValidatorOmitUint[T]) InSlice

func (validator *ValidatorOmitUint[T]) InSlice(slice []T, template ...string) *ValidatorOmitUint[T]

Validate if an optional number is present in a numeric slice. The validation only passes if the value is set and found in the provided slice. For example:

quantity := omit.Val[uint]{}
quantity.Set(3)
validQuantities := []uint{1,3,5}
Is(v.OmitUint(quantity).InSlice(validQuantities))

func (*ValidatorOmitUint[T]) LessOrEqualTo

func (validator *ValidatorOmitUint[T]) LessOrEqualTo(value T, template ...string) *ValidatorOmitUint[T]

Validate if an optional numeric value is less than or equal to another. This function internally uses the golang `<=` operator. The validation only passes if the value is set and less than or equal to the provided value. For example:

quantity := omit.Val[uint]{}
quantity.Set(2)
Is(v.OmitUint(quantity).LessOrEqualTo(2))

func (*ValidatorOmitUint[T]) LessThan

func (validator *ValidatorOmitUint[T]) LessThan(value T, template ...string) *ValidatorOmitUint[T]

Validate if an optional numeric value is less than another. This function internally uses the golang `<` operator. The validation only passes if the value is set and less than the provided value. For example:

quantity := omit.Val[uint]{}
quantity.Set(2)
Is(v.OmitUint(quantity).LessThan(3))

func (*ValidatorOmitUint[T]) Not

func (validator *ValidatorOmitUint[T]) Not() *ValidatorOmitUint[T]

Invert the logical value associated with the next validator function. For example:

// It will return false because Not() inverts the boolean value associated with the Zero() function
quantity := omit.Val[uint]{}
quantity.Set(0)
Is(v.OmitUint(quantity).Not().Zero()).Valid()

func (*ValidatorOmitUint[T]) Or

func (validator *ValidatorOmitUint[T]) Or() *ValidatorOmitUint[T]

Introduces a logical OR in the chain of validation conditions, affecting the evaluation order and priority of subsequent validators. A value passes the validation if it meets any one condition following the Or() call, adhering to a left-to-right evaluation. This mechanism allows for validating against multiple criteria where satisfying any single criterion is sufficient. Example:

// This validator will pass because the input is Zero.
input := omit.Val[uint]{}
input.Set(0)
isValid := v.Is(v.OmitUint(input).GreaterThan(5).Or().Zero()).Valid()

func (*ValidatorOmitUint[T]) Passing

func (validator *ValidatorOmitUint[T]) Passing(function func(v omit.Val[T]) bool, template ...string) *ValidatorOmitUint[T]

Validate if an optional numeric value passes a custom function. The validation only passes if the value is set and the custom function returns true. For example:

quantity := omit.Val[uint]{}
quantity.Set(2)
Is(v.OmitUint(quantity).Passing((v uint) bool {
	return v == getAllowedQuantity()
})

func (*ValidatorOmitUint[T]) Positive

func (validator *ValidatorOmitUint[T]) Positive(template ...string) *ValidatorOmitUint[T]

Validate if an optional numeric value is positive (greater than zero). The validation only passes if the value is set and greater than zero.

For example:

quantity := omit.Val[uint]{}
quantity.Set(5)
Is(v.OmitUint(quantity).Positive())

func (*ValidatorOmitUint[T]) Set

func (validator *ValidatorOmitUint[T]) Set(template ...string) *ValidatorOmitUint[T]

Validate if an optional numeric value is set. The validation only passes if the value is set. For example:

quantity := omit.Val[uint]{}
quantity.Set(5)
Is(v.OmitUint(quantity).Set())

func (*ValidatorOmitUint[T]) Zero

func (validator *ValidatorOmitUint[T]) Zero(template ...string) *ValidatorOmitUint[T]

Validate if an optional numeric value is zero. The validation only passes if the value is set and equal to zero.

For example:

quantity := omit.Val[uint]{}
quantity.Set(0)
Is(v.OmitUint(quantity).Zero())

Jump to

Keyboard shortcuts

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