validate

package
v2.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 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

func IsMemberOf added in v2.7.0

func IsMemberOf(claim string, claims ...string) bool

IsMemberOf returns true if claim is part of the list of claims

func NotEmpty

func NotEmpty(claims ...string) bool

NotEmpty test all provided values to be not empty

Types

type Assertion added in v2.7.0

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 added in v2.7.0

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

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

type Validator added in v2.7.0

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

Validator collects assertions

func New added in v2.7.0

func New(name string) *Validator

New initializes and returns a new Validator

func (*Validator) AsError added in v2.7.0

func (v *Validator) AsError() error

AsError returns an error if NError > 0, nil otherwise

func (*Validator) AssertContains added in v2.7.0

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

AssertContains verifies that a map contains key

func (*Validator) AssertError added in v2.7.0

func (v *Validator) AssertError(txt string)

AssertError add an error assertion

func (*Validator) AssertExistsError added in v2.7.0

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

AssertExistsError verifies that a struct exists

func (*Validator) AssertISO639 added in v2.7.0

func (v *Validator) AssertISO639(src string)

AssertISO639 verifies that src complies with ISO 639-1

func (*Validator) AssertNotEmpty added in v2.7.0

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

AssertNotEmpty verifies that a map is not empty

func (*Validator) AssertNotNil added in v2.7.0

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

AssertNotNil verifies that an attribute is not nil

func (*Validator) AssertNotZero added in v2.7.0

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

AssertNotZero verifies that a map is not empty

func (*Validator) AssertStringError added in v2.7.0

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

AssertStringError verifies a string

func (*Validator) AssertStringExists added in v2.7.0

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

AssertStringExists verifies a string is not empty

func (*Validator) AssertWarning added in v2.7.0

func (v *Validator) AssertWarning(txt string)

AssertWarning add an warning assertion

func (*Validator) Error added in v2.7.0

func (v *Validator) Error() string

Error returns an error text

func (*Validator) IsClean added in v2.7.0

func (v *Validator) IsClean() bool

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

func (*Validator) IsValid added in v2.7.0

func (v *Validator) IsValid() bool

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

func (*Validator) NErrors added in v2.7.0

func (v *Validator) NErrors() int

NErrors returns the number of erros

func (*Validator) NWarnings added in v2.7.0

func (v *Validator) NWarnings() int

NWarnings returns the number of warnings

func (*Validator) Report added in v2.7.0

func (v *Validator) Report() string

Report returns a description of all issues

func (*Validator) Validate added in v2.7.0

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