validate

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2017 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package validate provides utilities that allow to validate request and response data against OpenAPI Specification parameter and schema definitions.

Note that errors returned from validation functions are generally of type Error, so they can be asserted to corresponding interface(s) to retrieve error's field and value.

errs := validate.Query(ps, q)
for _, err := range errs {
    if e, ok := err.(validate.Error) {
        field, value := e.Field(), e.Value()
        // ...
    }
}

Index

Constants

View Source
const (
	// RFC3339PartialTime is partial-time format as described in RFC3339
	// https://xml2rfc.tools.ietf.org/public/rfc/html/rfc3339.html#anchor14
	RFC3339PartialTime = "15:04:05"
)

Variables

This section is empty.

Functions

func Body

func Body(ps []spec.Parameter, data interface{}) []error

Body validates request body by spec and returns errors if any.

func BySchema

func BySchema(sch *spec.Schema, data interface{}) []error

BySchema validates data by spec and returns errors if any.

func IsPartialTime

func IsPartialTime(value string) bool

IsPartialTime returns true when the string is a valid partial time.

func Query

func Query(ps []spec.Parameter, q url.Values) []error

Query validates request query parameters by spec and returns errors if any.

Types

type PartialTime

type PartialTime time.Time

PartialTime represents a partial-time defined in RFC3339.

swagger:strfmt partial-time

func (PartialTime) MarshalText

func (pt PartialTime) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler

func (PartialTime) String

func (pt PartialTime) String() string

String implements fmt.Stringer

func (*PartialTime) UnmarshalText

func (pt *PartialTime) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler

type ValidationError

type ValidationError interface {
	error

	// Field returns field name where error occurred.
	Field() string

	// Value returns original value passed by client on field where error
	// occurred.
	Value() interface{}
}

ValidationError describes validation error.

func ValidationErrorf

func ValidationErrorf(field string, value interface{}, format string, args ...interface{}) ValidationError

ValidationErrorf returns a new formatted ValidationError.

type ValidationErrors

type ValidationErrors []ValidationError

ValidationErrors is a set of validation errors.

func (ValidationErrors) Errors

func (es ValidationErrors) Errors() []error

Errors returns ValidationErrors in form of Go builtin errors.

Jump to

Keyboard shortcuts

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