validate

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2022 License: Apache-2.0 Imports: 4 Imported by: 153

Documentation

Index

Constants

This section is empty.

Variables

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

ErrFieldRequired reports that field is required, but not found.

Functions

This section is empty.

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 Int

type Int struct {
	MultipleOf    int
	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 int)

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

Jump to

Keyboard shortcuts

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