validate

package
v2.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 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 non-nil attribute '%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         = "no errors/warnings"
)

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
	// contains filtered or unexported fields
}

Assertion is used to collect validation information

func (*Assertion) ToString

func (a *Assertion) ToString() string

func (*Assertion) ToStringWithIndex

func (a *Assertion) ToStringWithIndex(i int) string

func (*Assertion) TypeAsString

func (a *Assertion) TypeAsString() string

type Validatable

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

Validatable is the interface that must be implemented to support (recursive) validations of structs

type Validator

type Validator struct {
	Issues   []*Assertion
	Errors   int
	Warnings int
	// contains filtered or unexported fields
}

Validator collects assertions

func NewValidator

func NewValidator() *Validator

NewValidator initializes and returns a new Validator

func (*Validator) AddError

func (v *Validator) AddError(txt string)

AddError adds an error assertion

func (*Validator) AddWarning

func (v *Validator) AddWarning(txt string)

AddWarning adds an warning assertion

func (*Validator) AsError

func (v *Validator) AsError() error

AsError returns an error if NError > 0, nil otherwise

func (*Validator) Context

func (v *Validator) Context() string

func (*Validator) Error

func (v *Validator) Error() string

Error returns an error text

func (*Validator) ISO639

func (v *Validator) ISO639(src string)

ISO639 verifies that src complies with ISO 639-1

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) MapContains

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

MapContains verifies that a map contains key

func (*Validator) MapNotEmpty

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

MapNotEmpty verifies that a map is not empty

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) NonZero

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

NonZero verifies that a map is not empty

func (*Validator) NotNil

func (v *Validator) NotNil(src interface{}, hint string)

NotNil verifies that an attribute is not nil

func (*Validator) RFC1123Z

func (v *Validator) RFC1123Z(src string)

RFC1123Z verifies that src complies with RFC 1123-Z

func (*Validator) Report

func (v *Validator) Report() string

Report returns a description of all issues

func (*Validator) RestoreContext

func (v *Validator) RestoreContext()

func (*Validator) SaveContext

func (v *Validator) SaveContext(ctx string)

func (*Validator) StringEquals

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

StringEquals verifies a string

func (*Validator) StringNotEmpty

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

StringNotEmpty verifies a string is not empty

func (*Validator) Timestamp

func (v *Validator) Timestamp(src string)

Timestamp validates that src is a valid UNIX timestamp

Jump to

Keyboard shortcuts

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