validator

package
v0.9.10 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AssertionWarning indicates a potential issue
	AssertionWarning = 0
	// AssertionError indicates an error in the validation
	AssertionError = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Assertion

type Assertion struct {
	Type int    // 0 == warning, 1 == error
	Txt  string // description of the problem
	Err  error
}

Assertion is used to collect validation information

type Validatable

type Validatable interface {
	Validate(*Validator) *Validator
}

Validatable is the interface that maust be implemented to support recursive validations of strucs

type Validator

type Validator struct {
	Name     string
	Issues   []*Assertion
	Errors   int
	Warnings int
}

Validator collects assertions

func New

func New(name string) *Validator

New initializes and returns a new Validator

func (*Validator) AsError

func (v *Validator) AsError() error

AsError returns an error if NError > 0, nil otherwise

func (*Validator) AssertContains

func (v *Validator) AssertContains(src map[string]string, key, name string)

AssertContains verifies that a map contains key

func (*Validator) AssertError

func (v *Validator) AssertError(txt string)

AssertError add an error assertion

func (*Validator) AssertExistsError

func (v *Validator) AssertExistsError(src interface{}, expected string)

AssertExistsError verifies that a struct exists

func (*Validator) AssertISO639

func (v *Validator) AssertISO639(src string)

AssertISO639 verifies that src complies with ISO 639-1

func (*Validator) AssertNotEmpty

func (v *Validator) AssertNotEmpty(src map[string]string, name string)

AssertNotEmpty verifies that a map is not empty

func (*Validator) AssertNotNil

func (v *Validator) AssertNotNil(src interface{}, name string)

AssertNotNil verifies that an attribute is not nil

func (*Validator) AssertNotZero

func (v *Validator) AssertNotZero(src int, name string)

AssertNotZero verifies that a map is not empty

func (*Validator) AssertStringError

func (v *Validator) AssertStringError(src, expected string)

AssertStringError verifies a string

func (*Validator) AssertStringExists

func (v *Validator) AssertStringExists(src, name string)

AssertStringExists verifies a string is not empty

func (*Validator) AssertWarning

func (v *Validator) AssertWarning(txt string)

AssertWarning add an warning assertion

func (*Validator) Error

func (v *Validator) Error() string

Error returns an error text

func (*Validator) IsClean

func (v *Validator) IsClean() bool

IsClean returns true if NError == 0 AND NWarnings == 0

func (*Validator) IsValid

func (v *Validator) IsValid() bool

IsValid returns true if NError == 0. Warnings are ignored

func (*Validator) NErrors

func (v *Validator) NErrors() int

NErrors returns the number of erros

func (*Validator) NWarnings

func (v *Validator) NWarnings() int

NWarnings returns the number of warnings

func (*Validator) Report

func (v *Validator) Report() string

Report returns a description of all issues

func (*Validator) Validate

func (v *Validator) Validate(src Validatable) *Validator

Validate starts the chain of validations

Jump to

Keyboard shortcuts

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