store

package module
v0.0.0-...-eb32ab8 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: Apache-2.0 Imports: 4 Imported by: 31

README

store

A library which serves storing data in a generic interface

// TODO update the watcher

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Key

type Key struct {
	types.NamespacedName
}

func KeyFromNSN

func KeyFromNSN(nsn types.NamespacedName) Key

KeyFromNSN takes a types.NamespacedName and returns it wrapped in the Key struct.

func ToKey

func ToKey(name string) Key

ToKey takes a resource name and returns a types.NamespacedName initialized with the name. The namespace attribute however is uninitialized.

func (Key) String

func (r Key) String() string

String returns the key as a string <namespace>.<name> or <name> depending on the presence of the namespace

type Storer

type Storer[T1 any] interface {
	// Retrieve retrieves data for the given key from the storage
	Get(ctx context.Context, key Key) (T1, error)

	// Retrieve retrieves data for the given key from the storage
	List(ctx context.Context, visitorFunc func(context.Context, Key, T1))

	// Retrieve retrieves data for the given key from the storage
	ListKeys(ctx context.Context) []string

	// Len returns the # entries in the store
	Len(ctx context.Context) int

	// Create data with the given key in the storage
	Create(ctx context.Context, key Key, data T1) error

	// Update data with the given key in the storage
	Update(ctx context.Context, key Key, data T1) error

	// Update data in a concurrent way through a function
	UpdateWithKeyFn(ctx context.Context, key Key, updateFunc func(ctx context.Context, obj T1) T1)

	// Delete deletes data and key from the storage
	Delete(ctx context.Context, key Key) error

	// Watch watches change
	Watch(ctx context.Context) (watch.Interface[T1], error)
}

Storer defines the interface for a generic storage system.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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