inspection

package
v0.0.0-...-c635e59 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: Apache-2.0, BSD-2-Clause Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapInspector

func MapInspector[K comparable, V any](mapToInspect mapInterface[K, V], inspect func(inspectedMap InspectedObject, key K, value V)) func(inspectedMap InspectedObject)

MapInspector is a utility function that can be used to create a manual inspection function for a map.

func SetInspector

func SetInspector[T comparable](setToInspect setInterface[T], inspect func(inspectedSet InspectedObject, element T)) func(inspectedSet InspectedObject)

SetInspector is a utility function that can be used to create a manual inspection function for a set.

Types

type Inspectable

type Inspectable interface {
	// Inspect returns the inspected version of the object.
	Inspect(session ...Session) InspectedObject
}

Inspectable is an interface that is used to represent an object that can be automatically inspected.

type InspectedObject

type InspectedObject interface {
	// Type returns the type of the object.
	Type() string

	// InstanceID returns the instance identifier of the object.
	InstanceID() string

	// Add adds a child object to the inspected object.
	Add(name string, instance any, inspectManually ...func(object InspectedObject))

	// Get returns the child object with the given name.
	Get(name string) (object InspectedObject, exists bool)

	// ForEach iterates through all child objects of the inspected object.
	ForEach(callback func(name string, child InspectedObject))

	// ReachableObjectsCount returns the number of reachable objects from the inspected object.
	ReachableObjectsCount() int

	// String returns a string representation of the inspected object.
	String() string
}

InspectedObject is an interface that is used to represent an object that has been inspected.

func NewInspectedObject

func NewInspectedObject(instance any, inspect func(InspectedObject), session ...Session) InspectedObject

NewInspectedObject creates a new inspected object from the given instance and inspect function.

type Session

type Session map[any]bool

Session is used to track instances of objects that have already been inspected.

func (Session) FirstOccurrence

func (s Session) FirstOccurrence(instance any) bool

FirstOccurrence checks if the given instance has already been inspected.

Jump to

Keyboard shortcuts

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