validate

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package validate provides a generic implementation for any object type using validation rules

Index

Constants

This section is empty.

Variables

View Source
var ErrConfig = errors.New("cannot validate, invalid configuration")

ErrConfig return this error if the configuration file is invalid

View Source
var ErrFailedRule = errors.New("Failed Rule")

ErrFailedRule return this error if an object fails a validation rule

Functions

func ConfigByField

func ConfigByField[T any](configReader io.Reader, fieldname string) (T, error)

ConfigByField get the config field name after decoding

func DenyFunc added in v0.2.0

func DenyFunc[S ~[]E, E any](target S, check func(E) error) error

DenyFunc generic execution of a check function over a slice of objects

func NewFailedRuleError

func NewFailedRuleError(rule string, id string) error

NewFailedRuleError convenience function for error wrapping

Types

type Validator

type Validator[ObjectT any, ConfigT any] struct {
	// contains filtered or unexported fields
}

Validator generic validation runner

func NewValidator

func NewValidator[ObjectT any, ConfigT any]() Validator[ObjectT, ConfigT]

NewValidator used to create specific implementations of a validator

func (Validator[ObjectT, ConfigT]) ReadConfigAndValidate

func (v Validator[ObjectT, ConfigT]) ReadConfigAndValidate(objects []ObjectT, configReader io.Reader, field string) error

ReadConfigAndValidate validate after decoding the configuration object

func (Validator[ObjectT, ConfigT]) Validate

func (v Validator[ObjectT, ConfigT]) Validate(objects []ObjectT, config ConfigT) error

Validate run validation rules on a slice of objects

func (Validator[ObjectT, ConfigT]) WithAllowRules

func (v Validator[ObjectT, ConfigT]) WithAllowRules(rules ...func(ObjectT, ConfigT) bool) Validator[ObjectT, ConfigT]

WithAllowRules define the allow rules which will skip validation

func (Validator[ObjectT, ConfigT]) WithValidationRules

func (v Validator[ObjectT, ConfigT]) WithValidationRules(rules ...func([]ObjectT, ConfigT) error) Validator[ObjectT, ConfigT]

WithValidationRules define the fail validation rules, all must pass

Jump to

Keyboard shortcuts

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