Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrKeyNotFound = errors.New("key not found")
Functions ¶
This section is empty.
Types ¶
type Binary ¶
type Binary interface {
encoding.BinaryMarshaler
encoding.BinaryUnmarshaler
}
Binary is an interface that represents a binary marshaler and unmarshaler.
type CodecBinary ¶
type CodecBinary[V encoding.BinaryMarshaler, VP binaryPointer[V]] struct{}
CodecBinary encodes/decodes Go values to/from binary.
func (CodecBinary[V, VP]) Marshal ¶
func (c CodecBinary[V, VP]) Marshal(v V) ([]byte, error)
Marshal encodes a Go value to JSON.
func (CodecBinary[V, VP]) Unmarshal ¶
func (c CodecBinary[V, VP]) Unmarshal(data []byte, v VP) error
Unmarshal decodes a JSON value into a Go value.
type CodecBytes ¶
type CodecBytes[V Bytes] struct{}
func (CodecBytes[V]) Marshal ¶
func (CodecBytes[V]) Marshal(v V) ([]byte, error)
Marshal implements kv.Codec.
func (CodecBytes[V]) Unmarshal ¶
func (CodecBytes[V]) Unmarshal(data []byte, v *V) error
Unmarshal implements kv.Codec.
type CodecGob ¶
type CodecGob[V any] struct{}
CodecGob encodes/decodes Go values to/from gob. You can use encoding.Gob instead of creating an instance of this struct.
type CodecJSON ¶
type CodecJSON[V any] struct{}
CodecJSON encodes/decodes Go values to/from JSON. You can use encoding.JSON instead of creating an instance of this struct.
type Store ¶
type Store[K any, V any] interface { // Set stores the given value for the given key. // The implementation automatically marshalls the value. // The marshalling format depends on the implementation. It can be JSON, gob, etc. Set(ctx context.Context, k K, v V) error // Get retrieves the value for the given key. // The implementation automatically unmarshalls the value. // The unmarshalling source depends on the implementation. It can be JSON, gob, etc. // The automatic unmarshalling requires a pointer to an object of the correct type // being passed as a parameter. // In the case of a struct, the Get method will populate the fields of the object // that the passed pointer points to with the values of the retrieved object's values. // If no value is found, it returns (false, nil). Get(ctx context.Context, k K) (V, error) // Delete deletes the stored value for the given key. // Deleting a non-existing key-value MUST NOT lead to an error. Delete(ctx context.Context, k K) error // Edit retrieves the value for the given key, calls the provided edit function with the value, Edit(ctx context.Context, k K, edit Edit[V]) error // Close must be called when the work with the key-value store is done. // // As the same interface is used for managing transactions, calling Close() will commit the transaction in this case. // Most other implementations are meant to be long-lived, so only call Close() at the very end. // // Some implementations might not need the store to be closed, // but as long as you work with the kv.Store interface, you never know which implementation // is passed to your method, so you should always call it. Close(ctx context.Context) error // Range iterates over all key-value pairs in the store and calls the provided iterator function for each pair. // The iterator function should return non-nil error to stop the iteration, is this case. This error will be returned by Range, its canonical to return [io.EOF] Range(ctx context.Context, iter Iter[K, V]) error // RangeWithPrefix iterates over all key-value pairs in the store that have the given prefix // and calls the provided iterator function for each pair. // The iterator function should return non-nil error to stop the iteration. RangeWithPrefix(ctx context.Context, prefix K, iter Iter[K, V]) error }
Store is an interface that represents a key-value store. It provides methods for storing, retrieving, and deleting key-value pairs. The implementation of the store can use different marshalling formats, such as JSON or gob. Generic type of the value must be non-pointer type, until implementation says otherwise.