kv

package
v0.0.33 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyValue

type KeyValue[T MarshalerUnmarshaler] struct {
	// contains filtered or unexported fields
}

func (*KeyValue[T]) Create

func (s *KeyValue[T]) Create(ctx context.Context, key string, value T) (revision uint64, err error)

func (*KeyValue[T]) Delete

func (s *KeyValue[T]) Delete(ctx context.Context, key string, opts ...nats.DeleteOpt) error

func (*KeyValue[T]) Get

func (s *KeyValue[T]) Get(ctx context.Context, key string) (T, uint64, error)

func (*KeyValue[T]) GetAll

func (s *KeyValue[T]) GetAll(ctx context.Context, keys []string) ([]T, error)

func (*KeyValue[T]) Keys

func (s *KeyValue[T]) Keys(ctx context.Context) ([]string, error)

func (*KeyValue[T]) LastRevision

func (s *KeyValue[T]) LastRevision(ctx context.Context, key string) (uint64, error)

func (*KeyValue[T]) Put

func (s *KeyValue[T]) Put(ctx context.Context, key string, value T) (revision uint64, err error)

func (*KeyValue[T]) Update

func (s *KeyValue[T]) Update(ctx context.Context, key string, value T, lastRevision uint64) (revision uint64, err error)

type KeyValuer

type KeyValuer[T any] interface {
	Keys(ctx context.Context) ([]string, error)
	Get(ctx context.Context, key string) (T, uint64, error)
	GetAll(ctx context.Context, keys []string) ([]T, error)
	Create(ctx context.Context, key string, value T) (revision uint64, err error)
	Put(ctx context.Context, key string, value T) (revision uint64, err error)
	Update(ctx context.Context, key string, value T, lastRevision uint64) (revision uint64, err error)
	// Status(ctx context.Context, key string) (nats.KeyValueStatus, error)
	LastRevision(context.Context, string) (uint64, error)
	Delete(ctx context.Context, key string, opts ...nats.DeleteOpt) error
}

func BucketKeyValuer

func BucketKeyValuer[T MarshalerUnmarshaler](conn *nats.Conn, name string) (KeyValuer[T], error)

func New

func New[T MarshalerUnmarshaler](kv nats.KeyValue) KeyValuer[T]

type Marshaler

type Marshaler interface {
	MarshalValue() ([]byte, error)
}

A Marshaler can encode itself into bytes. aggregates must implement Marshaler & Unmarshaler for Snapshots to work.

Example using encoding/gob:

type foo struct {
	aggregate.Aggregate
	state
}

type state struct {
	Name string
	Age uint8
}

func (f *foo) MarshalValue() ([]byte, error) {
	var buf bytes.Buffer
	err := gob.NewEncoder(&buf).Encode(f.state)
	return buf.Bytes(), err
}

func (f *foo) UnmarshalValue(p []byte) error {
	return gob.NewDecoder(bytes.NewReader(p)).Decode(&f.state)
}

type MarshalerUnmarshaler

type MarshalerUnmarshaler interface {
	Marshaler
	Unmarshaler
}

type NilValue

type NilValue struct{}

func (*NilValue) MarshalValue

func (*NilValue) MarshalValue() ([]byte, error)

func (*NilValue) UnmarshalValue

func (*NilValue) UnmarshalValue([]byte) error

type StringValue

type StringValue struct {
	Value string `json:"value"`
}

func (*StringValue) MarshalValue

func (v *StringValue) MarshalValue() ([]byte, error)

func (*StringValue) UnmarshalValue

func (v *StringValue) UnmarshalValue(b []byte) error

type UInt64Value

type UInt64Value struct {
	Value uint64 `json:"value"`
}

func (*UInt64Value) MarshalValue

func (v *UInt64Value) MarshalValue() ([]byte, error)

func (*UInt64Value) UnmarshalValue

func (v *UInt64Value) UnmarshalValue(b []byte) error

type Unmarshaler

type Unmarshaler interface {
	UnmarshalValue([]byte) error
}

An Unmarshaler can decode itself from bytes.

Jump to

Keyboard shortcuts

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