recstore

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package recstore provides a typed etcd storage for keys.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlreadyExistsTag

type AlreadyExistsTag struct{}

AlreadyExistsTag is an error tag that is returned when a key already exists.

type NotFoundTag

type NotFoundTag struct{}

NotFoundTag is an error tag for not found errors.

type RecStore

type RecStore[T any] struct {
	// contains filtered or unexported fields
}

RecStore is etcd record storage for the specific type.

func New

func New[T any](
	client clientv3.KV,
	name string,
	prefix string,
	marshal func(T) ([]byte, error),
	unmarshal func([]byte) (T, error),
) *RecStore[T]

New creates a new record store.

func (*RecStore[T]) Create

func (s *RecStore[T]) Create(ctx context.Context, val T) error

Create marshals and stores the value for the given key for the selected version. It returns an error if the key already exists.

func (*RecStore[T]) Get

func (s *RecStore[T]) Get(ctx context.Context) (Result[T], error)

Get retrieves and unmarshales the value for the given key.

func (*RecStore[T]) Update

func (s *RecStore[T]) Update(ctx context.Context, val T, version int64) error

Update marshals and stores the value for the given key for the selected version. If version is 0, it will create a new record. If version is not 0, it will update the record for the selected version.

type Result

type Result[T any] struct {
	Res     T
	Version int64
}

Result is a result of RecStore.Get.

type TxVersionConflictTag

type TxVersionConflictTag struct{}

TxVersionConflictTag is an error tag when version conflict that happens in a transaction.

type VersionConflictTag

type VersionConflictTag struct{}

VersionConflictTag is an error tag when the version of the record does not match the expected version.

Jump to

Keyboard shortcuts

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