Documentation ¶
Index ¶
- Variables
- func AllMatchRegex(values []string, regex *regexp.Regexp) (err error)
- func AreAllOneOf[T comparable](values, choices []T) (err error)
- func AreAllOneOfCaseInsensitive(values, choices []string) (err error)
- func DirectoryExists(path string) (err error)
- func FileExists(path string) (err error)
- func IsOneOf[T comparable](value T, possibilities ...T) (err error)
- func ListeningAddress(address string, uid int) (err error)
- func MatchRegex(value string, regex *regexp.Regexp) (err error)
- func NumberBetween[T constraints.Ordered](n, min, max T) (err error)
Constants ¶
This section is empty.
Variables ¶
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") )
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") )
var ( ErrPortNotAnInteger = errors.New("port value is not an integer") ErrPortTooHigh = errors.New("port cannot be higher than 65535") )
var (
ErrPrivilegedPort = errors.New("listening on privileged port is not allowed")
)
var ErrValueMismatchRegex = errors.New("value does not match regular expression")
var ErrValueOutOfBounds = errors.New("value is out of bounds")
Functions ¶
func AllMatchRegex ¶
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
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
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
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
ListeningAddress validates a listening address string given a user ID `uid`. If the address is empty, it is valid. If the port is 0, it is valid. If the port is below the start of unprivileged ports, it is valid if the user ID is 0 or -1 (windows); for any other user id, the running program Linux capabilities are checked to see if it can bind to privileged ports.
func MatchRegex ¶
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.