validationjuice

package
v1.17.9 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Description: This package contains functions that are used to validate nil values.

Description: This package provides a set of validators that can be used to validate struct fields. It also provides a registry to store and run these validators.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckNilValues

func CheckNilValues(params ...interface{}) error

CheckNilValues checks if any of the passed parameters are nil.

NOTE: Only parameters that have the possibility of being nil should be passed to this function. Passing a non-nil value of a type that cannot be nil (e.g., a string) will cause a panic.

Types

type Validator added in v1.15.12

type Validator func(fieldValue reflect.Value, fieldName string) error

Validator is a function type that performs validation on a string value.

The function returns an error if the validation fails.

func NewE164PhoneValidator

func NewE164PhoneValidator() Validator

NewE164Validator returns a validator that checks if a field is a string and is a valid E.164 phone number.

func NewNonNilPointerFieldElemIsUTCDateValidator

func NewNonNilPointerFieldElemIsUTCDateValidator() Validator

NewNonNilPointerFieldElemIsUTCDateValidator returns a validator that checks if a field is a pointer, is not nil, and its underlying value is a valid UTC date.

func NewNonNilPointerValidator

func NewNonNilPointerValidator() Validator

NewNonNilPointerValidator returns a validator that checks if a field is a pointer and is not nil.

func NewNonPointerFieldIntInsideRangeValidator added in v1.13.4

func NewNonPointerFieldIntInsideRangeValidator(min int, max int) Validator

NewNonPointerFieldIntInsideRangeValidator returns a validator that checks if a field is an int and is inside a given range.

func NewNonZeroPointerElemValidator

func NewNonZeroPointerElemValidator() Validator

NewNonNilPointerElemValidator returns a validator that checks if a field is a pointer, is not nil, and its underlying value is not zero.

func NewNonZeroValidator

func NewNonZeroValidator() Validator

NewNonZeroValidator returns a validator that checks if a field is not a pointer and is not zero.

func NewPointerFieldIntInsideRangeValidator added in v1.13.4

func NewPointerFieldIntInsideRangeValidator(min int, max int) Validator

NewPointerFieldIntInsideRangeValidator returns a validator that checks if a field is a pointer, is not nil, and its underlying value is an int inside a given range.

func NewPointerFieldIsValidBPC47Validator added in v1.14.6

func NewPointerFieldIsValidBPC47Validator() Validator

NewPointerFieldIsValidBPC47Validator returns a validator that checks if a field is a pointer, is not nil, and its underlying value is a valid BCP47 language tag.

type ValidatorRegistryInterface

type ValidatorRegistryInterface interface {
	AddValidator(string, Validator)
	RunTags(interface{}, string) error
}

ValidatorRegistryInterface is an interface that defines the methods that a validatorRegistry must implement.

func NewValidatorRegistry

func NewValidatorRegistry() ValidatorRegistryInterface

NewValidatorRegistry creates a new validatorRegistry and initializes its validators map.

It returns a ValidatorRegistryInterface.

Jump to

Keyboard shortcuts

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