Documentation
¶
Overview ¶
Package storage provides a pluggable storage layer for the chat application. It provides a pebble backend by default, but can be extended to support other storage backends as needed.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Backend ¶
type Backend[K, V any] interface { Get(ctx context.Context, key K) (value V, found bool, err error) Set(ctx context.Context, key K, value V) error Delete(ctx context.Context, key K) error List(ctx context.Context, pageSize *int, pageToken *K) (entries iter.Seq2[K, V], nextPageToken *K, err error) Flush(ctx context.Context) error Close(ctx context.Context) error }
type Codec ¶
type Codec[K, V any] interface { EncodeKey(K) ([]byte, error) DecodeKey([]byte) (K, error) EncodeValue(V) ([]byte, error) DecodeValue([]byte) (V, error) }
Codec is an interface for encoding and decoding keys and values for a storage backend. This could be a JSON codec, a binary codec, or any other serialization format that makes sense for your application.
type JSONCodec ¶
type JSONCodec[K, V any] struct{}
JSONCodec is a codec for encoding and decoding keys and values using standard Go JSON serialization.
func (*JSONCodec[K, V]) DecodeKey ¶
DecodeKey decodes a JSON byte slice into a key from a storage backend.
func (*JSONCodec[K, V]) DecodeValue ¶
DecodeValue decodes a JSON byte slice into a value from a storage backend.
func (*JSONCodec[K, V]) EncodeKey ¶
EncodeKey encodes a key into a JSON byte slice for a storage backend.
func (*JSONCodec[K, V]) EncodeValue ¶
EncodeValue encodes a value into a JSON byte slice for a storage backend.