validation

package
v8.4.0+incompatible Latest Latest
Warning

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

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

Documentation

Overview

Package validation provides methods for validating parameter value using reflection.

Index

Constants

View Source
const (
	Empty            = "Empty"
	Null             = "Null"
	ReadOnly         = "ReadOnly"
	Pattern          = "Pattern"
	MaxLength        = "MaxLength"
	MinLength        = "MinLength"
	MaxItems         = "MaxItems"
	MinItems         = "MinItems"
	MultipleOf       = "MultipleOf"
	UniqueItems      = "UniqueItems"
	InclusiveMaximum = "InclusiveMaximum"
	ExclusiveMaximum = "ExclusiveMaximum"
	ExclusiveMinimum = "ExclusiveMinimum"
	InclusiveMinimum = "InclusiveMinimum"
)

Constraint list

Variables

This section is empty.

Functions

func NewErrorWithValidationError

func NewErrorWithValidationError(err error, packageType, method string) error

NewErrorWithValidationError appends package type and method name in validation error.

func Validate

func Validate(m []Validation) error

Validate method validates constraints on parameter passed in validation array.

Types

type Constraint

type Constraint struct {

	// Target field name for validation.
	Target string

	// Constraint name e.g. minLength, MaxLength, Pattern, etc.
	Name string

	// Rule for constraint e.g. greater than 10, less than 5 etc.
	Rule interface{}

	// Chain Validations for struct type
	Chain []Constraint
}

Constraint stores constraint name, target field name Rule and chain validations.

type Validation

type Validation struct {
	TargetValue interface{}
	Constraints []Constraint
}

Validation stores parameter-wise validation.

Jump to

Keyboard shortcuts

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