object

package
v0.3.40 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

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

func Fix(elem Fixer, mustExists bool) error

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

func NewErrFix(field string, reason error) *ErrFix

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

func (e *ErrFix) ChangeReason(reason error)

ChangeReason implements the errors.Unwrapper interface.

func (*ErrFix) Error

func (e *ErrFix) Error() string

Error implements the errors.Unwrapper interface.

Message:

  • "failed to fix field <field>" if the reason is nil.
  • "field <field> failed to fix: <reason>" if the reason is not nil.

func (*ErrFix) Unwrap

func (e *ErrFix) Unwrap() error

Unwrap 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

func NewErrFixAt(field string, idx int, reason error) *ErrFixAt

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

func (e *ErrFixAt) ChangeReason(reason error)

ChangeReason implements the errors.Unwrapper interface.

func (*ErrFixAt) Error

func (e *ErrFixAt) Error() string

Error implements the errors.Unwrapper interface.

Message:

  • "failed to fix field <field> at index <idx>" if the reason is nil.
  • "field <field> at index <idx> failed to fix: <reason>" if the reason is not nil.

func (*ErrFixAt) Unwrap

func (e *ErrFixAt) Unwrap() error

Unwrap 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"

type Fixer

type Fixer interface {
	// Fix fixes the object.
	//
	// Returns:
	//   - error: An error if the object could not be fixed.
	Fix() error
}

Fixer is an interface for objects that can be fixed.

Jump to

Keyboard shortcuts

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