validators

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2021 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Duration

type Duration func(time.Duration) error

A Duration validator should return an error if the time.Duration provided is not considered valid, nil otherwise.

func DurationMax

func DurationMax(max time.Duration) Duration

DurationMax creates a Duration validator that fails when the time.Duration is strictly more than `max`.

func DurationMin

func DurationMin(min time.Duration) Duration

DurationMin creates a Duration validator that fails when the time.Duration is strictly less than `min`.

func DurationRange

func DurationRange(min, max time.Duration) Duration

DurationRange creates a Duration validator that fails when the time.Duration is strictly less than `min` or strictly more than `max`.

func DurationRounded

func DurationRounded(r time.Duration) Duration

DurationRounded creates a Duration validator that fails when the time.Duration is not a multiple of `r`

type Float64

type Float64 func(float64) error

A Float64 validator should return an error if the float64 provided is not considered valid, nil otherwise.

func Float64Max

func Float64Max(max float64) Float64

Float64Max creates a Float64 validator that fails when the float64 is strictly larger than `max`.

func Float64Min

func Float64Min(min float64) Float64

Float64Min creates a Float64 validator that fails when the float64 is strictly smaller than `min`.

func Float64Range

func Float64Range(min, max float64) Float64

Float64Range creates a Float64 validator that fails when the float64 is strictly smaller than `min` or strictly larger than `max`.

type Int

type Int func(int) error

A Int validator should return an error if the int provided is not considered valid, nil otherwise.

func IntMax

func IntMax(max int) Int

IntMax creates a Int validator that fails when the int is strictly larger than `max`.

func IntMin

func IntMin(min int) Int

IntMin creates a Int validator that fails when the int is strictly smaller than `min`.

func IntRange

func IntRange(min, max int) Int

IntRange creates a Int validator that fails when the int is strictly smaller than `min` or strictly larger than `max`.

type Int64

type Int64 func(int64) error

A Int64 validator should return an error if the int64 provided is not considered valid, nil otherwise.

func Int64Max

func Int64Max(max int64) Int64

Int64Max creates a Int64 validator that fails when the int64 is strictly larger than `max`.

func Int64Min

func Int64Min(min int64) Int64

Int64Min creates a Int64 validator that fails when the int64 is strictly smaller than `min`.

func Int64Range

func Int64Range(min, max int64) Int64

Int64Range creates a Int64 validator that fails when the int64 is strictly smaller than `min` or strictly larger than `max`.

type Regexp

type Regexp func(*regexp.Regexp) error

A Regexp validator should return an error if the *regexp.Regexp provided is not considered valid, nil otherwise.

type Repeatable

type Repeatable func(interface{}) error

A Repeatable validator should return an error if the value provided is not considered valid, nil otherwise. This validator is used on individual values of a rig.Repeatable

func ToRepeatable

func ToRepeatable(validator interface{}) Repeatable

ToRepeatable turns some validator (i.e a func(int) error) into a validators.Repeatable (func(interface{}) error), removing the need to implement separate validators when dealing with repeatables.

type String

type String func(string) error

A String validator should return an error if the string provided is not considered valid, nil otherwise.

func StringExcludeChars

func StringExcludeChars(chars string) String

StringExcludeChars creates a String validator that fails when the string contains one ore more of the characters in `chars`.

func StringExcludePrefix

func StringExcludePrefix(prefix string) String

StringExcludePrefix creates a String validator that fails when the string starts with `prefix`.

func StringExcludeSuffix

func StringExcludeSuffix(suffix string) String

StringExcludeSuffix creates a String validator that fails when the string ends with `suffix`.

func StringLengthMax

func StringLengthMax(max int) String

StringLengthMax creates a String validator that fails when the string is strictly longer than `max`.

func StringLengthMin

func StringLengthMin(min int) String

StringLengthMin creates a String validator that fails when the string is strictly shorter than `min`.

func StringLengthRange

func StringLengthRange(min, max int) String

StringLengthRange creates a String validator that fails when the string is strictly shorter than `min` or strictly longer than `max`.

func StringNotEmpty

func StringNotEmpty() String

StringNotEmpty creates a String validator that fails when the string is empty (after calling strings.TrimSpace).

type URL

type URL func(*url.URL) error

A URL validator should return an error if the *url.URL provided is not considered valid, nil otherwise.

func URLExcludeScheme

func URLExcludeScheme(scheme string) URL

URLExcludeScheme creates a URL validator that fails when the url.URL uses the scheme `scheme`. The validator never fails of `scheme` is empty.

func URLScheme

func URLScheme(scheme string) URL

URLScheme creates a URL validator that fails when the url.URL does not use the scheme `scheme`. The validator never fails of `scheme` is empty.

type Uint

type Uint func(uint) error

A Uint validator should return an error if the uint provided is not considered valid, nil otherwise.

func UintMax

func UintMax(max uint) Uint

UintMax creates a Uint validator that fails when the uint is strictly larger than `max`.

func UintMin

func UintMin(min uint) Uint

UintMin creates a Uint validator that fails when the uint is strictly smaller than `min`.

func UintRange

func UintRange(min, max uint) Uint

UintRange creates a Uint validator that fails when the uint is strictly smaller than `min` or strictly larger than `max`.

type Uint64

type Uint64 func(uint64) error

A Uint64 validator should return an error if the uint64 provided is not considered valid, nil otherwise.

func Uint64Max

func Uint64Max(max uint64) Uint64

Uint64Max creates a Uint64 validator that fails when the uint64 is strictly larger than `max`.

func Uint64Min

func Uint64Min(min uint64) Uint64

Uint64Min creates a Uint64 validator that fails when the uint64 is strictly smaller than `min`.

func Uint64Range

func Uint64Range(min, max uint64) Uint64

Uint64Range creates a Uint64 validator that fails when the uint64 is strictly smaller than `min` or strictly larger than `max`.

type Var

type Var func(flag.Value) error

A Var validator should return an error if the flag.Value provided is not considered valid, nil otherwise.

Jump to

Keyboard shortcuts

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