req

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Overview

package req provides request body validation facilities. Using struct tags you may define rules in order to validate structured user input.

Index

Constants

View Source
const (
	// StructTagName is the name of the tags package req bases its behavior
	// on.
	StructTagName = "req"
	// StructTagNonZero indicates that a field with a zero value shall fail
	// validation.
	StructTagNonZero = "nonzero"
)

Variables

View Source
var (
	ErrUnsupportedType    = errors.New("unsupported type")
	ErrUnknownDirective   = errors.New("unknown directive")
	ErrTestNonZeroIsZero  = errors.New("value is zero")
	ErrCannotValidateType = errors.New("cannot validate type")
)

Functions

func GetSchema

func GetSchema(dst io.Writer, typ reflect.Type) error

GetSchema writes to `dst` a JSON-like schema of type `typ`. It returns nil iff it finished writing the schema. It returns an error instead.

Types

type FieldValidationError

type FieldValidationError struct {
	Field reflect.StructField
	Err   error
}

FieldValidationError signals that a field failed to validate.

func (FieldValidationError) Error

func (fve FieldValidationError) Error() string

type ValidationError

type ValidationError []error

ValidationError is an error representing one or more validation errors.

func (ValidationError) Error

func (ve ValidationError) Error() string

type Validator

type Validator func(interface{}) error

Validator validates a value, returning nil in case of success.

func CreateValidator

func CreateValidator(example interface{}) (Validator, error)

CreateValidator creates a validator for the type of its argument.

Jump to

Keyboard shortcuts

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