Documentation ¶
Index ¶
- Variables
- func Comparable[T Numeric](val T) numeric[T]
- func DirExists(path string) error
- func FileExists(path string) error
- func InRange[T Numeric](min, max, val T, opts ...InRangeOpt) error
- func IsSupportedValue[T comparable](value T, supportedValues ...T) error
- func NotBlank(val string) error
- func NotEmpty(val string) error
- func NotEmptySlice[T any](slice []T) error
- func PathIsAbs(path string) error
- type InRangeOpt
- type Numeric
- type ValidationError
- type ValidationErrors
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotSet should be used when the value is not set, but it is required. ErrNotSet = errors.New("not set") // ErrBlankOrEmpty should be used when non-blank/non-empty string is expected. ErrBlankOrEmpty = errors.New("blank or empty") // ErrDoesntExist should be used when resource doesn't exist. ErrDoesntExist = errors.New("doesn't exist") // ErrNotDir should be used when path on the file system exists, but it is not a directory. ErrNotDir = errors.New("not a dir") // ErrNotFile should be used when path on the file system exists, but it is not a file. ErrNotFile = errors.New("not a file") // ErrNotAbsolutePath should be used in case absolute path is expected, but the relative was provided. ErrNotAbsolutePath = errors.New("not an absolute path") // ErrNotUnique should be used when the value must be unique, but there are duplicates. ErrNotUnique = errors.New("not unique") // ErrBadOrder should be used when the order of the elements is wrong. ErrBadOrder = errors.New("bad order") // ErrNotInRange should be used when the value is not in expected range of values. ErrNotInRange = errors.New("not in range") // ErrUnsupportedValue should be used when the value is not supported. ErrUnsupportedValue = errors.New("not supported") )
Functions ¶
func Comparable ¶
func Comparable[T Numeric](val T) numeric[T]
Comparable wraps value, so the method can be invoked on it.
func FileExists ¶
FileExists checks the value points to an existing file on the disk.
func InRange ¶
func InRange[T Numeric](min, max, val T, opts ...InRangeOpt) error
InRange returns an error if 'val' is less than 'min' or greater or equal to 'max'.
func IsSupportedValue ¶
func IsSupportedValue[T comparable](value T, supportedValues ...T) error
IsSupportedValue ensures the provided 'value' is one listed as 'supportedValues'.
func NotEmptySlice ¶
NotEmptySlice returns an error if provided slice has no elements.
Types ¶
type InRangeOpt ¶
type InRangeOpt int
InRangeOpt represents configuration options for InRange function.
const ( // InRangeOptIncludeMin includes min value equality. InRangeOptIncludeMin InRangeOpt = iota + 1 // InRangeOptIncludeMax includes max value equality. InRangeOptIncludeMax )
type Numeric ¶
type Numeric interface { constraints.Integer | constraints.Float }
Numeric includes types that can be used in the comparison operations.
type ValidationError ¶
type ValidationError struct { // Key represents a path to the field. Key []string // Cause contains a reason why validation failed. Cause error }
ValidationError represents an issue with provided configuration.
func NewValidationError ¶
func NewValidationError(err error, keys ...string) ValidationError
NewValidationError creates a new ValidationError with provided parameters.
func (ValidationError) Error ¶
func (ve ValidationError) Error() string
Error to implement an error standard interface. The string representation can have 3 different formats: - when Key and Cause is set: "outer.inner: failure cause" - when only Key is set: "outer.inner" - when only Cause is set: "failure cause"
type ValidationErrors ¶
type ValidationErrors []ValidationError
ValidationErrors is a list of ValidationError-s.
func (ValidationErrors) Append ¶
func (vs ValidationErrors) Append(err error, keys ...string) ValidationErrors
Append adds provided error into current list by enriching each ValidationError with the provided keys or if provided err is not an instance of the ValidationError it will be wrapped into it. In case the nil is provided nothing happens.
func (ValidationErrors) AsError ¶
func (vs ValidationErrors) AsError() error
AsError returns nil if there are no elements and itself if there is at least one.
func (ValidationErrors) Error ¶
func (vs ValidationErrors) Error() string
Error transforms all validation errors into a single string joined by newline.