Documentation
¶
Index ¶
- func CleanChannel[T any](ch chan T) chan T
- func CleanMap[K comparable, V Cleaner](elems map[K]V) map[K]V
- func CleanMapOf[K comparable, V any](elems map[K]V) map[K]V
- func CleanSimple[T comparable](elem T) T
- func CleanSlice[T Cleaner](elems []T) []T
- func CleanSliceOf[T any](elems []T) []T
- func Fix(elem Fixer, mustExists bool) error
- type Cleaner
- type ErrFix
- type ErrFixAt
- type ErrValueMustExists
- type Fixer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanChannel ¶ added in v0.3.37
func CleanChannel[T any](ch chan T) chan T
CleanChannel cleans a channel.
Parameters:
- ch: The channel to clean.
Returns:
- chan T: The cleaned channel.
func CleanMap ¶ added in v0.3.37
func CleanMap[K comparable, V Cleaner](elems map[K]V) map[K]V
CleanMap cleans a map of elements.
Parameters:
- elems: The map of elements to clean.
Returns:
- map[K]V: The cleaned map of elements.
func CleanMapOf ¶ added in v0.3.37
func CleanMapOf[K comparable, V any](elems map[K]V) map[K]V
CleanMapOf cleans a map of elements.
Parameters:
- elems: The map of elements to clean.
Returns:
- map[K]V: The cleaned map of elements.
func CleanSimple ¶ added in v0.3.37
func CleanSimple[T comparable](elem T) T
CleanSimple cleans a simple element.
Parameters:
- elem: The element to clean.
Returns:
- T: The cleaned element.
func CleanSlice ¶ added in v0.3.37
func CleanSlice[T Cleaner](elems []T) []T
CleanSlice cleans a slice of elements.
Parameters:
- elems: The slice of elements to clean.
Returns:
- []T: The cleaned slice of elements.
func CleanSliceOf ¶ added in v0.3.37
func CleanSliceOf[T any](elems []T) []T
CleanSliceOf cleans a slice of elements.
Parameters:
- elems: The slice of elements to clean.
Returns:
- []T: The cleaned slice of elements.
func Fix ¶
Fix fixes an object if it exists.
Parameters:
- elem: The object to fix.
- mustExists: A flag indicating if the object must exist.
Returns:
- error: An error if the object could not be fixed.
Behaviors:
- Returns an error if the object must exist but does not.
- Returns nil if the object is nil and does not need to exist.
Types ¶
type Cleaner ¶ added in v0.3.37
type Cleaner interface {
// Cleanup cleans the object.
Cleanup()
}
Cleaner is an interface for objects that can be cleaned.
type ErrFix ¶
type ErrFix struct { // Field is the field that could not be fixed. Field string // Reason is the reason the field could not be fixed. Reason error }
ErrFix is an error indicating that a field could not be fixed.
func NewErrFix ¶
NewErrFix creates a new ErrFix error.
Parameters:
- field: The field that could not be fixed.
- reason: The reason the field could not be fixed.
Returns:
- *ErrFix: The new error.
func (*ErrFix) ChangeReason ¶
ChangeReason implements the errors.Unwrapper interface.
type ErrFixAt ¶
type ErrFixAt struct { // Field is the field that could not be fixed. Field string // Idx is the index of the field that could not be fixed. Idx int // Reason is the reason the field could not be fixed. Reason error }
ErrFixAt is an error indicating that a field at an index could not be fixed.
func NewErrFixAt ¶
NewErrFixAt creates a new ErrFixAt error.
Parameters:
- field: The field that could not be fixed.
- idx: The index of the field that could not be fixed.
- reason: The reason the field could not be fixed.
Returns:
- *ErrFixAt: The new error.
func (*ErrFixAt) ChangeReason ¶
ChangeReason implements the errors.Unwrapper interface.
type ErrValueMustExists ¶
type ErrValueMustExists struct{}
ErrValueMustExists is an error indicating that a value must exist.
func NewErrValueMustExists ¶
func NewErrValueMustExists() *ErrValueMustExists
NewErrValueMustExists creates a new ErrValueMustExists error.
Returns:
- *ErrValueMustExists: The new error.
func (*ErrValueMustExists) Error ¶
func (e *ErrValueMustExists) Error() string
Error implements the error interface.
Message: "value must exists"