validate

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: Apache-2.0 Imports: 7 Imported by: 153

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBodyRequired = errors.New("body required")

ErrBodyRequired reports that request body is required but server got empty request.

View Source
var ErrFieldRequired = errors.New("field required")

ErrFieldRequired reports that field is required, but not found.

Functions

func InvalidContentType added in v0.11.1

func InvalidContentType(contentType string) error

InvalidContentType creates new InvalidContentTypeError.

func UnexpectedStatusCode added in v0.11.1

func UnexpectedStatusCode(statusCode int) error

UnexpectedStatusCode creates new UnexpectedStatusCode.

Types

type Array

type Array struct {
	MinLength    int
	MinLengthSet bool
	MaxLength    int
	MaxLengthSet bool
}

Array validates array length.

func (Array) Set

func (t Array) Set() bool

Set reports whether any validations are set.

func (*Array) SetMaxLength

func (t *Array) SetMaxLength(v int)

SetMaxLength sets MaxLength validation.

func (*Array) SetMinLength

func (t *Array) SetMinLength(v int)

SetMinLength sets MinLength validation.

func (Array) ValidateLength

func (t Array) ValidateLength(v int) error

ValidateLength returns error if array length v is invalid.

type Error

type Error struct {
	Fields []FieldError
}

Error represents validation error.

func (*Error) Error

func (e *Error) Error() string

Error implements error.

type FieldError

type FieldError struct {
	Name  string
	Error error
}

FieldError is failed validation on field.

type Float added in v0.16.0

type Float struct {
	MultipleOf    *big.Rat
	MultipleOfSet bool

	Min          float64
	MinSet       bool
	MinExclusive bool

	Max          float64
	MaxSet       bool
	MaxExclusive bool
}

Float validates float numbers.

func (Float) Set added in v0.16.0

func (t Float) Set() bool

Set reports whether any validations are set.

func (*Float) SetExclusiveMaximum added in v0.16.0

func (t *Float) SetExclusiveMaximum(v float64)

SetExclusiveMaximum sets exclusive maximum value.

func (*Float) SetExclusiveMinimum added in v0.16.0

func (t *Float) SetExclusiveMinimum(v float64)

SetExclusiveMinimum sets exclusive minimum value.

func (*Float) SetMaximum added in v0.16.0

func (t *Float) SetMaximum(v float64)

SetMaximum sets maximum value.

func (*Float) SetMinimum added in v0.16.0

func (t *Float) SetMinimum(v float64)

SetMinimum sets minimum value.

func (*Float) SetMultipleOf added in v0.16.0

func (t *Float) SetMultipleOf(rat *big.Rat)

SetMultipleOf sets multipleOf validator.

func (Float) Validate added in v0.16.0

func (t Float) Validate(v float64) error

Validate returns error if v does not match validation rules.

type Int

type Int struct {
	MultipleOf    uint64
	MultipleOfSet bool

	Min          int64
	MinSet       bool
	MinExclusive bool

	Max          int64
	MaxSet       bool
	MaxExclusive bool
}

Int validates integers.

func (Int) Set

func (t Int) Set() bool

Set reports whether any validations are set.

func (*Int) SetExclusiveMaximum

func (t *Int) SetExclusiveMaximum(v int64)

SetExclusiveMaximum sets exclusive maximum value.

func (*Int) SetExclusiveMinimum

func (t *Int) SetExclusiveMinimum(v int64)

SetExclusiveMinimum sets exclusive minimum value.

func (*Int) SetMaximum

func (t *Int) SetMaximum(v int64)

SetMaximum sets maximum value.

func (*Int) SetMinimum

func (t *Int) SetMinimum(v int64)

SetMinimum sets minimum value.

func (*Int) SetMultipleOf

func (t *Int) SetMultipleOf(v uint64)

SetMultipleOf sets multipleOf validator.

func (Int) Validate

func (t Int) Validate(v int64) error

Validate returns error if v does not match validation rules.

type InvalidContentTypeError added in v0.11.1

type InvalidContentTypeError struct {
	ContentType string
}

InvalidContentTypeError reports that decoder got unexpected content type.

func (*InvalidContentTypeError) Error added in v0.11.1

func (i *InvalidContentTypeError) Error() string

InvalidContentTypeError implements error.

type Object added in v0.12.0

type Object struct {
	MinProperties    int
	MinPropertiesSet bool
	MaxProperties    int
	MaxPropertiesSet bool
}

Object validates map length.

func (Object) Set added in v0.12.0

func (t Object) Set() bool

Set reports whether any validations are set.

func (*Object) SetMaxProperties added in v0.12.0

func (t *Object) SetMaxProperties(v int)

SetMaxProperties sets MaxProperties validation.

func (*Object) SetMinProperties added in v0.12.0

func (t *Object) SetMinProperties(v int)

SetMinProperties sets MinProperties validation.

func (Object) ValidateProperties added in v0.12.0

func (t Object) ValidateProperties(v int) error

ValidateProperties returns error if object length (properties number) v is invalid.

type String

type String struct {
	MinLength    int
	MinLengthSet bool
	MaxLength    int
	MaxLengthSet bool
	Email        bool
	Regex        *regexp.Regexp
	Hostname     bool
}

String validator.

func (String) Set

func (t String) Set() bool

Set reports whether any validations are set.

func (*String) SetMaxLength

func (t *String) SetMaxLength(v int)

SetMaxLength sets maximum string length (in Unicode code points).

func (*String) SetMinLength

func (t *String) SetMinLength(v int)

SetMinLength sets minimum string length (in Unicode code points).

func (String) Validate

func (t String) Validate(v string) error

Validate returns error if v does not match validation rules.

type UnexpectedStatusCodeError added in v0.11.1

type UnexpectedStatusCodeError struct {
	StatusCode int
}

UnexpectedStatusCodeError reports that client got unexpected status code.

func (*UnexpectedStatusCodeError) Error added in v0.11.1

func (i *UnexpectedStatusCodeError) Error() string

UnexpectedStatusCodeError implements error.

Jump to

Keyboard shortcuts

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