storebackend

package
v0.0.0-...-a69e604 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 5 Imported by: 23

Documentation

Index

Constants

View Source
const (
	ErrNotFound int = iota + 1
	ErrAlreadyExists
	ErrInvalidObj
	ErrTimeout
)

Variables

This section is empty.

Functions

func IsExist

func IsExist(err error) bool

IsExist returns true if and only if err is "key" already exists error.

func IsInvalidObj

func IsInvalidObj(err error) bool

IsInvalidObj returns true if and only if err is invalid error

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if and only if err is "key" not found error.

func IsRequestTimeout

func IsRequestTimeout(err error) bool

IsRequestTimeout returns true if and only if err indicates that the request has timed out.

Types

type Config

type Config[T1 any] struct {
	GroupResource schema.GroupResource
	Prefix        string
	Codec         runtime.Codec
	NewFunc       func() runtime.Object
}

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

type StorageError

type StorageError struct {
	Code               int
	Key                string
	AdditionalErrorMsg string
}

func NewAlreadyExistsError

func NewAlreadyExistsError(key string) *StorageError

func NewInvalidObjError

func NewInvalidObjError(key, msg string) *StorageError

func NewNotFoundError

func NewNotFoundError(key string) *StorageError

func (*StorageError) Error

func (r *StorageError) Error() string

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)) error

	// 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
	UpdateWithFn(ctx context.Context, updateFunc func(ctx context.Context, key Key, obj T1) 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) error

	// Delete deletes data and key from the storage
	Delete(ctx context.Context, key Key) 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