state

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyAlreadyExists = errors.New("key already exists")

ErrKeyAlreadyExists is returned when a key already exists in a store and cannot be created.

View Source
var ErrKeyNotFound = errors.New("key not found")

ErrKeyNotFound is returned when a key is not found in a store.

View Source
var ErrRevisionMismatch = errors.New("revision mismatch")

ErrRevisionMismatch is returned when a revision does not match the current revision of a key.

View Source
var ErrStoreNotFound = &validationError{err: "store not found"}

ErrStoreNotFound is returned when a store is not found.

View Source
var Module = fx.Module(
	"state",
	fx.Provide(sprout.Logger("state"), fx.Private),
	fx.Provide(sprout.ServiceTracer(), fx.Private),
	fx.Provide(NewManager),
)

Functions

func IsValidKey

func IsValidKey(name string) bool

IsValidKey checks if the key name is valid. The NATS documentation says that keys follow the same rules as subjects so we delegate to events.IsValidSubject.

func IsValidStoreName

func IsValidStoreName(name string) bool

IsValidStoreName checks if the store name is valid.

func IsValidationError

func IsValidationError(err error) bool

Types

type Entry

type Entry struct {
	Timestamp time.Time
	Revision  uint64
	Value     *anypb.Any
}

type KeyDeleteEvent

type KeyDeleteEvent struct {
	Key      string
	Revision uint64
}

type KeyEvent

type KeyEvent interface {
	// contains filtered or unexported methods
}

type KeySetEvent

type KeySetEvent struct {
	Key      string
	Revision uint64
	Value    []byte
}

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(
	logger *zap.Logger,
	tracer trace.Tracer,
	js jetstream.JetStream,
) (*Manager, error)

NewManager creates a new state manager.

func (*Manager) Create

func (m *Manager) Create(ctx context.Context, store string, key string, value *anypb.Any) (uint64, error)

Create creates the value for the given key in the given store. If the key already exists, ErrKeyAlreadyExists is returned.

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, store string, key string) error

Delete deletes the value for the given key in the given store.

func (*Manager) DeleteWithRevision

func (m *Manager) DeleteWithRevision(ctx context.Context, store string, key string, revision uint64) error

DeleteWithRevision deletes the value for the given key in the given store only if the revision matches.

func (*Manager) Destroy

func (m *Manager) Destroy()

func (*Manager) EnsureStore

func (m *Manager) EnsureStore(ctx context.Context, config *StoreConfig) error

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, store string, key string) (*Entry, error)

Get returns the value for the given key in the given store. If the key doesn't exist, ErrKeyNotFound is returned.

func (*Manager) Set

func (m *Manager) Set(ctx context.Context, store string, key string, value *anypb.Any) (uint64, error)

Set sets the value for the given key in the given store.

func (*Manager) Update

func (m *Manager) Update(ctx context.Context, store string, key string, value *anypb.Any, revision uint64) (uint64, error)

Update updates the value for the given key in the given store only if the revision matches.

func (*Manager) Watch

func (m *Manager) Watch(ctx context.Context, store string, key string) (*Watcher, error)

Watch watches the given store for changes.

func (*Manager) WatchAll

func (m *Manager) WatchAll(ctx context.Context, store string) (*Watcher, error)

type SetResult

type SetResult struct {
	Revision uint64
}

type StoreConfig

type StoreConfig struct {
	Name string
}

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

func (*Watcher) Stop

func (w *Watcher) Stop() error

func (*Watcher) Updates

func (w *Watcher) Updates() <-chan KeyEvent

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳