storage

package
v0.0.0-...-ae24e80 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: MPL-2.0 Imports: 3 Imported by: 0

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

func PageSize

func PageSize(pageSize int) *int

func PageToken

func PageToken[T any](pageToken T) *T

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 Entry

type Entry[K, V any] struct {
	Key   K
	Value V
}

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

func (c *JSONCodec[K, V]) DecodeKey(data []byte) (K, error)

DecodeKey decodes a JSON byte slice into a key from a storage backend.

func (*JSONCodec[K, V]) DecodeValue

func (c *JSONCodec[K, V]) DecodeValue(data []byte) (V, error)

DecodeValue decodes a JSON byte slice into a value from a storage backend.

func (*JSONCodec[K, V]) EncodeKey

func (c *JSONCodec[K, V]) EncodeKey(key K) ([]byte, error)

EncodeKey encodes a key into a JSON byte slice for a storage backend.

func (*JSONCodec[K, V]) EncodeValue

func (c *JSONCodec[K, V]) EncodeValue(value V) ([]byte, error)

EncodeValue encodes a value into a JSON byte slice for a storage backend.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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