storage

package
v0.0.0-...-06858c0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventType

type EventType string

EventType is an enum type to declare the different causes of a monitoring event.

const (
	Creation     EventType = "creation"
	Deletion     EventType = "deletion"
	Periodically EventType = "periodically"
)

type Storage

type Storage[T any] interface {
	// List returns all objects from the storage.
	List() []T

	// Add adds an object to the storage.
	// It overwrites the old object if one with the same id was already stored.
	Add(id string, o T)

	// Get returns an object from the storage.
	// Iff the object does not exist in the storage, ok will be false.
	Get(id string) (o T, ok bool)

	// Delete deletes the object with the passed id from the storage.
	// It does nothing if no object with the id is present in the store.
	Delete(id string)

	// Pop deletes the object with the given id from the storage and returns it.
	// Iff no such execution exists, ok is false and true otherwise.
	Pop(id string) (o T, ok bool)

	// Purge removes all objects from the storage.
	Purge()

	// Length returns the number of currently stored objects in the storage.
	Length() uint

	// Sample returns and removes an arbitrary object from the storage.
	// ok is true iff an object was returned.
	Sample() (o T, ok bool)
}

Storage is an interface for storing objects.

func NewLocalStorage

func NewLocalStorage[T any]() Storage[T]

NewLocalStorage responds with a Storage implementation. This implementation stores the data thread-safe in the local application memory.

func NewMonitoredLocalStorage

func NewMonitoredLocalStorage[T any](ctx context.Context, measurement string, callback WriteCallback[T], additionalEvents time.Duration) Storage[T]

NewMonitoredLocalStorage responds with a Storage implementation. All write operations are monitored in the passed measurement. Iff callback is set, it will be called on a write operation. Iff additionalEvents not zero, the duration will be used to periodically send additional monitoring events.

type WriteCallback

type WriteCallback[T any] func(p *write.Point, object T, eventType EventType)

WriteCallback is called before an event gets monitored. Iff eventType is Periodically it is no object provided.

Jump to

Keyboard shortcuts

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