validate

package
v0.4.0-rc5 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: MIT Imports: 9 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoChoice      = errors.New("one or more values is set but there is no possible value available")
	ErrValueNotOneOf = errors.New("value is not one of the possible choices")
)
View Source
var (
	ErrFileDoesNotExist = errors.New("file does not exist")
	ErrFileStat         = errors.New("failed stating file")
	ErrFilePathIsDir    = errors.New("filepath is a directory")
	ErrFilepathIsFile   = errors.New("filepath is a file")
)
View Source
var (
	ErrPortNotAnInteger = errors.New("port value is not an integer")
	ErrPortTooHigh      = errors.New("port cannot be higher than 65535")
	ErrPrivilegedPort   = errors.New("cannot use privileged ports (1 to 1023) when running without root")
)
View Source
var ErrValueMismatchRegex = errors.New("value does not match regular expression")
View Source
var ErrValueOutOfBounds = errors.New("value is out of bounds")

Functions

func AllMatchRegex

func AllMatchRegex(values []string, regex *regexp.Regexp) (err error)

AllMatchRegex returns a `nil` error if all the given `values` match the given `regex`. Otherwise, an error is returned, wrapping `ErrValueMismatchRegex` and describing details on the mismatch.

func AreAllOneOf added in v0.2.0

func AreAllOneOf[T comparable](values, choices []T) (err error)

AreAllOneOf returns a `nil` error if each of the `values` are one of the given `choices`. Otherwise, an error is returned, wrapping `ErrValueNotOneOf`, precising which value did not match and listing the `possibilities`.

func AreAllOneOfCaseInsensitive added in v0.3.0

func AreAllOneOfCaseInsensitive(values, choices []string) (err error)

AreAllOneOfCaseInsensitive returns a `nil` error if each of the `values` are one of the given `choices` in a case insensitive manner. Otherwise, an error is returned, wrapping `ErrValueNotOneOf`, precising which value did not match and listing the `possibilities`.

func DirectoryExists added in v0.3.0

func DirectoryExists(path string) (err error)

DirectoryExists returns a `nil` error if the given `path` exists and is a directory. Otherwise, an error is returned, wrapping either `ErrFileDoesNotExist`, `ErrFileStat` or `ErrFilepathIsFile`.

func FileExists added in v0.3.0

func FileExists(path string) (err error)

FileExists returns a `nil` error if the given `path` exists and is a file. Otherwise, an error is returned, wrapping either `ErrFileDoesNotExist`, `ErrFileStat` or `ErrFilePathIsDir`.

func IsOneOf

func IsOneOf[T comparable](value T, possibilities ...T) (err error)

IsOneOf returns a `nil` error if the `value` is one of the given `possibilities`. Otherwise, an error is returned, wrapping `ErrValueNotOneOf` and listing the `possibilities`.

func ListeningAddress added in v0.3.0

func ListeningAddress(address string, uid int, allowedPrivilegedPorts ...uint16) (err error)

ListeningAddress validates a listening address string given a user ID `uid` and an optional list of allowed privileged ports.

func MatchRegex

func MatchRegex(value string, regex *regexp.Regexp) (err error)

MatchRegex returns a `nil` error if the given `value` matches the given `regex`. Otherwise, an error is returned, wrapping `ErrValueMismatchRegex` and describing details on the mismatch.

func NumberBetween added in v0.2.0

func NumberBetween[T constraints.Ordered](n, min, max T) (err error)

NumberBetween returns a `nil` error if the given `n` is between the given `min` and `max` values. Otherwise, an error is returned, wrapping `ErrValueOutOfBounds` and describing details on the mismatch.

Types

This section is empty.

Jump to

Keyboard shortcuts

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