storage

package
v0.0.0-...-f6e13ef Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppendableStorage

type AppendableStorage interface {
	Storage
	Append(ctx context.Context, key string, data []byte) error
}

AppendableStorage is an interface for special storage systems that allow data to be atomically appended to a value.

type MapStorage

type MapStorage struct {
	// contains filtered or unexported fields
}

MapStorage is a toy storage system. All data is stored in memory via a single golang map that is trivially synchronized.

func NewMapStorage

func NewMapStorage() *MapStorage

NewMapStorage instantiates MapStorage.

func (*MapStorage) Append

func (ms *MapStorage) Append(ctx context.Context, key string, value []byte) error

Append atomically appends data to the specified key-value pair.

func (*MapStorage) Close

func (ms *MapStorage) Close(ctx context.Context) error

func (*MapStorage) Get

func (ms *MapStorage) Get(ctx context.Context, key []byte) ([]byte, error)

Get retrieves the key in the underlying map.

func (*MapStorage) GetData

func (ms *MapStorage) GetData() map[string][]byte

GetData is useful for debugging

func (*MapStorage) Put

func (ms *MapStorage) Put(ctx context.Context, key []byte, value []byte) error

Put stores the key-value pair in the underlying map.

type Storage

type Storage interface {
	// Get returns the value associated with a certain key.
	Get(ctx context.Context, key []byte) ([]byte, error)

	// Put maps a key to a value, creating a new mapping if the key is not
	// already mapped.
	Put(ctx context.Context, key []byte, value []byte) error

	// Closes the database.
	Close(ctx context.Context) error
}

Storage is an interface for an internally synchronized key-value storage system that a server can use to store data.

func OpenFile

func OpenFile(path string) Storage

OpenFile initializes a storage at provided path.

func Wrap

func Wrap(db *leveldb.DB) Storage

Wrap takes in a leveldb and turns it into a storage.

Jump to

Keyboard shortcuts

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