validate

package
v0.0.0-...-cdf09a4 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package validate contains validation helpers.

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.

View Source
var ErrNilPointer = errors.New("nil pointer")

ErrNilPointer reports that use Validate, but receiver pointer is nil.

Functions

func InvalidContentType

func InvalidContentType(contentType string) error

InvalidContentType creates new InvalidContentTypeError.

func UnexpectedStatusCode

func UnexpectedStatusCode(statusCode int) error

UnexpectedStatusCode creates new UnexpectedStatusCode.

func UniqueItems

func UniqueItems[S ~[]T, T comparable](arr S) error

UniqueItems ensures given array has no duplicates.

Types

type Array

type Array struct {
	MinLength    int
	MinLengthSet bool
	MaxLength    int
	MaxLengthSet bool
	UniqueItems  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) SetUniqueItems

func (t *Array) SetUniqueItems(v bool)

SetUniqueItems sets UniqueItems 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

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

func (t Float) Set() bool

Set reports whether any validations are set.

func (*Float) SetExclusiveMaximum

func (t *Float) SetExclusiveMaximum(v float64)

SetExclusiveMaximum sets exclusive maximum value.

func (*Float) SetExclusiveMinimum

func (t *Float) SetExclusiveMinimum(v float64)

SetExclusiveMinimum sets exclusive minimum value.

func (*Float) SetMaximum

func (t *Float) SetMaximum(v float64)

SetMaximum sets maximum value.

func (*Float) SetMinimum

func (t *Float) SetMinimum(v float64)

SetMinimum sets minimum value.

func (*Float) SetMultipleOf

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

SetMultipleOf sets multipleOf validator.

func (Float) Validate

func (t Float) Validate(v float64) error

Validate returns error if v does not match validation rules.

func (Float) ValidateStringified

func (t Float) ValidateStringified(v float64) error

ValidateStringified 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

type InvalidContentTypeError struct {
	ContentType string
}

InvalidContentTypeError reports that decoder got unexpected content type.

func (*InvalidContentTypeError) Error

func (e *InvalidContentTypeError) Error() string

InvalidContentTypeError implements error.

type MaxLengthError

type MaxLengthError struct {
	Len       int
	MaxLength int
}

MaxLengthError reports that len greater than maximum.

func (*MaxLengthError) Error

func (e *MaxLengthError) Error() string

MaxLengthError implements error.

type MinLengthError

type MinLengthError struct {
	Len       int
	MinLength int
}

MinLengthError reports that len less than minimum.

func (*MinLengthError) Error

func (e *MinLengthError) Error() string

MinLengthError implements error.

type NoRegexMatchError

type NoRegexMatchError struct{}

NoRegexMatchError reports that value have no regexp match.

func (*NoRegexMatchError) Error

func (*NoRegexMatchError) Error() string

MaxLengthError implements error.

type Object

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

Object validates map length.

func (Object) Set

func (t Object) Set() bool

Set reports whether any validations are set.

func (*Object) SetMaxProperties

func (t *Object) SetMaxProperties(v int)

SetMaxProperties sets MaxProperties validation.

func (*Object) SetMinProperties

func (t *Object) SetMinProperties(v int)

SetMinProperties sets MinProperties validation.

func (Object) ValidateProperties

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        ogenregex.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

type UnexpectedStatusCodeError struct {
	StatusCode int
}

UnexpectedStatusCodeError reports that client got unexpected status code.

func (*UnexpectedStatusCodeError) Error

func (e *UnexpectedStatusCodeError) Error() string

UnexpectedStatusCodeError implements error.

Jump to

Keyboard shortcuts

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