storage

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 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 NullStorage

type NullStorage[T object] struct{}

NullStorage is a dummy object honoring the Storage interface, and can be used in unit tests as a drop-in replacement in the dependencies if the test don't actually care about storage actions.

func (NullStorage[T]) Close

func (s NullStorage[T]) Close() error

func (NullStorage[T]) HealthCheck

func (s NullStorage[T]) HealthCheck(context.Context, func() T) bool

func (NullStorage[T]) Hydrate

func (s NullStorage[T]) Hydrate(context.Context, T) error

func (NullStorage[T]) Init

func (s NullStorage[T]) Init() error

func (NullStorage[T]) Save

func (s NullStorage[T]) Save(context.Context, T) error

type Storage

type Storage[T object] interface {
	// Init initialises the storage (opens it)
	Init() error
	// Close gracefully terminates the storage.
	Close() error
	// Hydrate hydrates the provided object with data coming from the storage
	// the provided object should at least be able to return a non-null and unique Identifier (via the GetIdentifier() method)
	Hydrate(ctx context.Context, defaultObj T) error
	// Save store the provided object in the storage
	// the provided object should at least be able to return a non-null and unique Identifier (via the GetIdentifier() method)
	Save(ctx context.Context, obj T) error
	// HealthCheck verifies if the storage is connected and usable
	HealthCheck(ctx context.Context, hydrationSample func() T) bool
}

func New

func New[T object](ctx context.Context, persistentStateDir string) Storage[T]

New returns an instance of the storage (it doesn't open it)

Jump to

Keyboard shortcuts

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