cfgerror

package
v15.11.13 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 DirExists

func DirExists(path string) error

DirExists checks the value points to an existing directory on the disk.

func FileExists

func FileExists(path string) error

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 NotBlank

func NotBlank(val string) error

NotBlank checks the value is not empty or blank.

func NotEmpty

func NotEmpty(val string) error

NotEmpty checks if value is empty.

func NotEmptySlice

func NotEmptySlice[T any](slice []T) error

NotEmptySlice returns an error if provided slice has no elements.

func PathIsAbs

func PathIsAbs(path string) error

PathIsAbs checks if provided path is an absolute path.

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 New

func New() ValidationErrors

New returns uninitialized ValidationErrors object.

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.

Jump to

Keyboard shortcuts

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