Categorygithub.com/gonobo/validator
repositorypackage
0.0.6
Repository: https://github.com/gonobo/validator.git
Documentation: pkg.go.dev

# README

validator

Test GoDoc Release

A simple library for validating conditions. Conditions are defined with rules; If the rule fails, an error is returned.

Installation

go get github.com/gonobo/validator

Usage

err := validator.Validate(
	validator.Rule(false, "must be false"),
)

if errors.Is(err, validator.ErrInvalid) {
	// handle validation error
}

The validator package also provides a function Any() that returns the first error encountered, or nil if all rules pass.

err := validator.Validate(
	validator.Any(
		validator.Rule(false, "must be false"),
		validator.Rule(true, "must be true"),
	),
) // returns "validation error: must be false"

The validator package also provides a function All() that evaluates all rules in the list:

err := validator.Validate(
	validator.All(
		validator.Rule(true, "must be true"),
		validator.Rule(false, "must be false"),
	),
) // returns "validation error: must be false"

if errors.Is(err, validator.ErrInvalid) {
	// handle validation error
}