validation

package
v2.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

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

Chain represents list of validators and is used to accumulate errors and return them as a single "error"

func New

func New(opts ...ChainOption) *Chain

New creates a new validation chain.

func (*Chain) AddAssertion

func (c *Chain) AddAssertion(isTrue bool, message string) *Chain

AddAssertion adds assertion to the validation chain.

func (*Chain) AddValidator

func (c *Chain) AddValidator(v Validator) *Chain

AddValidator adds validator to the validation chain.

func (*Chain) Validate

func (c *Chain) Validate() error

Validate runs validation chain and returns resulting error(s). It returns all validation error by default, use FailFast option to stop validation on first error.

type ChainOption

type ChainOption func(*Chain)

ChainOption configures a validation chain at creation time.

func AllErrors

func AllErrors() ChainOption

AllErrors sets whether a chain should return all errors.

func FailFast

func FailFast() ChainOption

FailFast sets whether a chain should stop validation on first error.

type TCPAddressValidator added in v2.2.1

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

TCPAddressValidator helps validate a TCP address

func NewTCPAddressValidator added in v2.2.1

func NewTCPAddressValidator(address string) *TCPAddressValidator

NewTCPAddressValidator creates an instance of TCPAddressValidator

func (*TCPAddressValidator) Validate added in v2.2.1

func (a *TCPAddressValidator) Validate() error

Validate implements validation.Validator.

type Validator

type Validator interface {
	Validate() error
}

Validator interface generalizes the validator implementations

func NewBooleanValidator

func NewBooleanValidator(boolCheck bool, errMessage string) Validator

NewBooleanValidator creates a new boolean validator that returns an error message if condition is false This validator will come handy when dealing with conditional validation

func NewConditionalValidator

func NewConditionalValidator(condition bool, validator Validator) Validator

NewConditionalValidator creates a conditional validator, that runs the validator if the condition is true. This validator will help when performing data update

func NewEmptyStringValidator

func NewEmptyStringValidator(fieldName, fieldValue string) Validator

NewEmptyStringValidator creates a string a emptyString validator

Jump to

Keyboard shortcuts

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