validate

package
v2.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2021 License: MIT Imports: 6 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

	MsgStringMismatch      = "expected '%s', found '%s'"
	MsgNonEmptyString      = "expected non empty string '%s'"
	MsgNotNil              = "expected not-nil attribute, got '%s'"
	MsgNonZero             = "expected non-zero value '%s'"
	MsgInvalidLanguageCode = "invalid language code '%s'"
	MsgInvalidTimestamp    = "invalid timestamp '%d'"
	MsgNonEmptyMap         = "expected none empty map '%s'"
	MsgExpectedKey         = "expected key '%s' in map '%s'"
	MsgEmptyReport         = "validation '%s' has zero errors/warnings"
)

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) AddError added in v2.7.1

func (v *Validator) AddError(txt string)

AddError adds an error assertion

func (*Validator) AddWarning added in v2.7.1

func (v *Validator) AddWarning(txt string)

AddWarning adds an warning assertion

func (*Validator) AsError added in v2.7.0

func (v *Validator) AsError() error

AsError returns an error if NError > 0, nil otherwise

func (*Validator) Error added in v2.7.0

func (v *Validator) Error() string

Error returns an error text

func (*Validator) ISO639 added in v2.7.1

func (v *Validator) ISO639(src string)

ISO639 verifies that src complies with ISO 639-1

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) MapContains added in v2.7.1

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

MapContains verifies that a map contains key

func (*Validator) MapNotEmpty added in v2.7.1

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

MapNotEmpty verifies that a map is not empty

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) NonZero added in v2.7.1

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

NonZero verifies that a map is not empty

func (*Validator) NotNil added in v2.7.1

func (v *Validator) NotNil(src interface{})

NotNil verifies that an attribute is not nil

func (*Validator) RFC1123Z added in v2.7.1

func (v *Validator) RFC1123Z(src string)

RFC1123Z verifies that src complies with RFC 1123-Z

func (*Validator) Report added in v2.7.0

func (v *Validator) Report() string

Report returns a description of all issues

func (*Validator) StringEquals added in v2.7.1

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

StringEquals verifies a string

func (*Validator) StringNotEmpty added in v2.7.1

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

StringNotEmpty verifies a string is not empty

func (*Validator) Timestamp added in v2.7.1

func (v *Validator) Timestamp(src string)

Timestamp validates that src is a valid UNIX timestamp

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