Documentation ¶
Overview ¶
Package storage provides a key-value storage abstraction where values are JSON-serializable structs. It is used by git-spice to store metadata in a git repository. It requires all write operations to have a message.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotExist = errors.New("does not exist in store")
ErrNotExist indicates that a key that was expected to exist does not exist.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface { // Get retrieves a value from the store // and decodes it into dst. // // If the key does not exist, Get returns ErrNotExist. Get(ctx context.Context, key string, dst any) error Update(ctx context.Context, req UpdateRequest) error Clear(ctx context.Context, msg string) error // Keys lists the keys in the store in the given directory, // with the directory prefix removed. // // The directory is defined as '/'-separated components in the key. // If dir is empty, all keys are listed. Keys(ctx context.Context, dir string) ([]string, error) }
Backend defines the primitive operations for the key-value store.
type DB ¶
type DB struct{ Backend }
DB is a high-level wrapper around a Backend. It provides a more convenient API for interacting with the store.
type GitBackend ¶
type GitBackend struct {
// contains filtered or unexported fields
}
GitBackend implements a storage backend using a Git repository reference as the storage medium.
func NewGitBackend ¶
func NewGitBackend(cfg GitConfig) *GitBackend
NewGitBackend creates a new GitBackend that stores data in the given Git repository.
func (*GitBackend) Clear ¶
func (g *GitBackend) Clear(ctx context.Context, msg string) error
Clear removes all keys from the store.
func (*GitBackend) Get ¶
func (g *GitBackend) Get(ctx context.Context, key string, v interface{}) error
Get retrieves a value from the store and decodes it into v.
func (*GitBackend) Update ¶
func (g *GitBackend) Update(ctx context.Context, req UpdateRequest) error
Update applies a batch of changes to the store.
type GitConfig ¶
type GitConfig struct { Repo GitRepository Ref string AuthorName, AuthorEmail string Log *log.Logger }
GitConfig is used to configure a GitBackend.
type GitRepository ¶
type GitRepository interface { PeelToCommit(ctx context.Context, ref string) (git.Hash, error) PeelToTree(ctx context.Context, ref string) (git.Hash, error) HashAt(ctx context.Context, commitish, path string) (git.Hash, error) ReadObject(ctx context.Context, typ git.Type, hash git.Hash, dst io.Writer) error WriteObject(ctx context.Context, typ git.Type, src io.Reader) (git.Hash, error) ListTree(ctx context.Context, tree git.Hash, opts git.ListTreeOptions) ([]git.TreeEntry, error) CommitTree(ctx context.Context, req git.CommitTreeRequest) (git.Hash, error) UpdateTree(ctx context.Context, req git.UpdateTreeRequest) (git.Hash, error) MakeTree(ctx context.Context, ents []git.TreeEntry) (git.Hash, error) SetRef(ctx context.Context, req git.SetRefRequest) error }
GitRepository is the subset of the git.Repository API used by the state package.
type MemBackend ¶
type MemBackend struct {
// contains filtered or unexported fields
}
MemBackend is an in-memory storage backend.
func (*MemBackend) Clear ¶
func (m *MemBackend) Clear(context.Context, string) error
Clear clears all keys in the store.
func (*MemBackend) Update ¶
func (m *MemBackend) Update(ctx context.Context, req UpdateRequest) error
Update applies a batch of changes to the store.
type SetRequest ¶
SetRequest is a single operation to add or update a key.
type UpdateRequest ¶
type UpdateRequest struct { Sets []SetRequest // Deletes lists the keys to delete. Deletes []string // Message to attach to the batch oepration. Message string }
UpdateRequest performs a batch of write operations in one transaction.