validation

package
v0.0.0-...-678bb0e Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2017 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package validation provides a helper for performing config validations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	Logger logging.Logger // logs errors as they appear
	// contains filtered or unexported fields
}

Context is an accumulator for validation errors.

It is passed to a function that does config validation. Such function may validate a bunch of files (using SetFile to indicate which one is processed now). Each file may have some internal nested structure. The logical path inside this structure is captured through Enter and Exit calls.

func (*Context) Enter

func (v *Context) Enter(title string, args ...interface{})

Enter descends into a sub-element when validating a nested structure.

Useful for defining context. A current path of elements shows up in validation messages.

The reverse is Exit.

func (*Context) Error

func (v *Context) Error(msg string, args ...interface{})

Error records a validation error.

func (*Context) Exit

func (v *Context) Exit()

Exit pops the current element we are visiting from the stack.

This is the reverse of Enter. Each Enter must have corresponding Exit. Use functions and defers to ensure this, if it's otherwise hard to track.

func (*Context) Finalize

func (v *Context) Finalize() error

Finalize returns *Error if some validation errors were recorded.

Returns nil otherwise.

func (*Context) SetFile

func (v *Context) SetFile(path string)

SetFile records that what follows is errors for this particular file.

Changing the file resets the current element (see Enter/Exit).

type Error

type Error struct {
	// Errors is a list of individual validation errors.
	//
	// Each one is annotated with "file" string and a logical path pointing to
	// the element that contains the error. It is provided as a slice of strings
	// in "element" annotation.
	Errors errors.MultiError
}

Error is an error with details of failed validation.

Returned by Context.Finalize().

func (*Error) Error

func (v *Error) Error() string

Error makes *Error implement 'error' interface.

Jump to

Keyboard shortcuts

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