validate

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2017 License: MIT Imports: 5 Imported by: 24 modules, 67 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

github.com/markbates/going/validate

This package has moved to https://github.com/markbates/validate.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Errors

type Errors struct {
	Errors map[string][]string `json:"errors"`
	Lock   *sync.RWMutex       `json:"-"`
}

Errors holds onto all of the error messages that get generated during the validation process.

func NewErrors

func NewErrors() *Errors

NewErrors returns a pointer to a Errors object that has been primed and ready to go.

func Validate

func Validate(validators ...Validator) *Errors

Validate takes in n number of Validator objects and will run them and return back a point to a Errors object that will contain any errors.

func (*Errors) Add

func (v *Errors) Add(key string, msg string)

Add will add a new message to the list of errors using the given key. If the key already exists the message will be appended to the array of the existing messages.

func (*Errors) Append

func (v *Errors) Append(ers *Errors)

Append concatenates two Errors objects together. This will modify the first object in place.

func (*Errors) Count

func (v *Errors) Count() int

Count returns the number of errors.

func (*Errors) Error

func (v *Errors) Error() string

Error implements the error interface

func (*Errors) Get

func (v *Errors) Get(key string) []string

Get returns an array of error messages for the given key.

func (*Errors) HasAny

func (v *Errors) HasAny() bool

HasAny returns true/false depending on whether any errors have been tracked.

func (*Errors) String

func (v *Errors) String() string

type Validator

type Validator interface {
	IsValid(errors *Errors)
}

Validator must be implemented in order to pass the validator object into the Validate function.

func ValidatorFunc

func ValidatorFunc(fn func(errors *Errors)) Validator

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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