storage

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2019 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const Delimiter = '/'

Delimiter separates nested paths in storage

View Source
const LookupLimit = 1000

LookupLimit is enforced by storage implementations

Variables

View Source
var ErrEmptyKey = errs.Class("empty key")

ErrEmptyKey is returned when an empty key is used in Put

View Source
var ErrEmptyQueue = errs.Class("empty queue")

ErrEmptyQueue is returned when attempting to Dequeue from an empty queue

View Source
var ErrInvalidBlobRef = errs.Class("invalid blob ref")

ErrInvalidBlobRef is returned when an blob reference is invalid

View Source
var ErrKeyNotFound = errs.Class("key not found")

ErrKeyNotFound used When something doesn't exist

View Source
var ErrLimitExceeded = errors.New("limit exceeded")

ErrLimitExceeded is returned when request limit is exceeded

Functions

func PutAll

func PutAll(store KeyValueStore, items ...ListItem) error

PutAll adds multiple values to the store

Types

type BlobReader

type BlobReader interface {
	io.Reader
	io.ReaderAt
	io.Seeker
	io.Closer
	// Size returns the size of the blob
	Size() (int64, error)
}

BlobReader is an interface that groups Read, ReadAt, Seek and Close.

type BlobRef

type BlobRef struct {
	Namespace []byte
	Key       []byte
}

BlobRef is a reference to a blob

func (*BlobRef) IsValid

func (ref *BlobRef) IsValid() bool

IsValid returns whether both namespace and key are specified

type BlobWriter

type BlobWriter interface {
	io.Writer
	// Cancel discards the blob.
	Cancel() error
	// Commit ensures that the blob is readable by others.
	Commit() error
	// Size returns the size of the blob
	Size() (int64, error)
}

BlobWriter is an interface that groups Read, ReadAt, Seek and Close.

type Blobs

type Blobs interface {
	// Create creates a new blob that can be written
	// optionally takes a size argument for performance improvements, -1 is unknown size
	Create(ctx context.Context, ref BlobRef, size int64) (BlobWriter, error)
	// Open opens a reader with the specified namespace and key
	Open(ctx context.Context, ref BlobRef) (BlobReader, error)
	// Delete deletes the blob with the namespace and key
	Delete(ctx context.Context, ref BlobRef) error
	// FreeSpace return how much free space left for writing
	FreeSpace() (int64, error)
}

Blobs is a blob storage interface

type Items

type Items []ListItem

Items keeps all ListItem

func CloneItems

func CloneItems(items Items) Items

CloneItems creates a deep copy of items

func ListV2

func ListV2(store KeyValueStore, opts ListOptions) (result Items, more bool, err error)

ListV2 lists all keys corresponding to ListOptions limit is capped to LookupLimit

more indicates if the result was truncated. If false then the result []ListItem includes all requested keys. If true then the caller must call List again to get more results by setting `StartAfter` or `EndBefore` appropriately.

func ReverseItems

func ReverseItems(items Items) Items

ReverseItems reverses items in the list items will be reused and modified TODO: remove this

func SelectPrefixed

func SelectPrefixed(items Items, prefix []byte) Items

SelectPrefixed keeps only items that have prefix items will be reused and modified TODO: remove this

func SortAndCollapse

func SortAndCollapse(items Items, prefix []byte) Items

SortAndCollapse sorts items and combines elements based on Delimiter items will be reused and modified TODO: remove this

func (Items) GetKeys

func (items Items) GetKeys() Keys

GetKeys gets all the Keys in []ListItem and converts them to Keys

func (Items) Len

func (items Items) Len() int

Len is the number of elements in the collection.

func (Items) Less

func (items Items) Less(i, k int) bool

Less reports whether the element with index i should sort before the element with index j.

func (Items) Swap

func (items Items) Swap(i, k int)

Swap swaps the elements with indexes i and j.

type IterateOptions

type IterateOptions struct {
	// Prefix ensure
	Prefix Key
	// First will be the first item iterator returns or the next item (previous when reverse)
	First Key
	// Recurse, do not collapse items based on Delimiter
	Recurse bool
	// Reverse iterates in reverse order
	Reverse bool
}

IterateOptions contains options for iterator

type Iterator

type Iterator interface {
	// Next prepares the next list item
	// returns false when you reach final item
	Next(item *ListItem) bool
}

Iterator iterates over a sequence of ListItems

type IteratorFunc

type IteratorFunc func(item *ListItem) bool

IteratorFunc implements basic iterator

func (IteratorFunc) Next

func (next IteratorFunc) Next(item *ListItem) bool

Next returns the next item

type Key

type Key []byte

Key is the type for the keys in a `KeyValueStore`

func AfterPrefix

func AfterPrefix(key Key) Key

AfterPrefix returns the key after prefix

func CloneKey

func CloneKey(key Key) Key

CloneKey creates a copy of key

func NextKey

func NextKey(key Key) Key

NextKey returns the successive key

func (Key) Equal

func (key Key) Equal(b Key) bool

Equal returns whether key and b are equal

func (Key) IsZero

func (key Key) IsZero() bool

IsZero returns true if the key struct is it's zero value

func (Key) Less

func (key Key) Less(b Key) bool

Less returns whether key should be sorted before b

func (Key) MarshalBinary

func (key Key) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface for the Key type

func (Key) String

func (key Key) String() string

String implements the Stringer interface

type KeyValueStore

type KeyValueStore interface {
	// Put adds a value to store
	Put(Key, Value) error
	// Get gets a value to store
	Get(Key) (Value, error)
	// GetAll gets all values from the store
	GetAll(Keys) (Values, error)
	// Delete deletes key and the value
	Delete(Key) error
	// List lists all keys starting from start and upto limit items
	List(start Key, limit int) (Keys, error)
	// Iterate iterates over items based on opts
	Iterate(opts IterateOptions, fn func(Iterator) error) error
	// Close closes the store
	Close() error
}

KeyValueStore describes key/value stores like redis and boltdb

type Keys

type Keys []Key

Keys is the type for a slice of keys in a `KeyValueStore`

func ListKeys

func ListKeys(store KeyValueStore, first Key, limit int) (Keys, error)

ListKeys returns keys starting from first and upto limit limit is capped to LookupLimit

func ReverseKeys

func ReverseKeys(keys Keys) Keys

ReverseKeys reverses the list of keys

func ReverseListKeys

func ReverseListKeys(store KeyValueStore, first Key, limit int) (Keys, error)

ReverseListKeys returns keys starting from first and upto limit in reverse order limit is capped to LookupLimit

func (Keys) ByteSlices

func (keys Keys) ByteSlices() [][]byte

ByteSlices converts a `Keys` struct to a slice of byte-slices (i.e. `[][]byte`)

func (Keys) Strings

func (keys Keys) Strings() []string

Strings returns everything as strings

type ListItem

type ListItem struct {
	Key      Key
	Value    Value
	IsPrefix bool
}

ListItem returns Key, Value, IsPrefix

func CloneItem

func CloneItem(item ListItem) ListItem

CloneItem creates a deep copy of item

func (ListItem) Less

func (item ListItem) Less(b ListItem) bool

Less returns whether item should be sorted before b

type ListOptions

type ListOptions struct {
	Prefix       Key
	StartAfter   Key // StartAfter is relative to Prefix
	EndBefore    Key // EndBefore is relative to Prefix
	Recursive    bool
	IncludeValue bool
	Limit        int
}

ListOptions are items that are optional for the LIST method

type Queue

type Queue interface {
	//Enqueue add a FIFO element
	Enqueue(Value) error
	//Dequeue removes a FIFO element, returning ErrEmptyQueue if empty
	Dequeue() (Value, error)
	//Peekqueue returns 'limit' elements from the queue
	Peekqueue(limit int) ([]Value, error)
	//Close closes the store
	Close() error
}

Queue is an interface describing queue stores like redis

type StaticIterator

type StaticIterator struct {
	Items Items
	Index int
}

StaticIterator implements an iterator over list of items

func (*StaticIterator) Next

func (it *StaticIterator) Next(item *ListItem) bool

Next returns the next item from the iterator

type Value

type Value []byte

Value is the type for the values in a `ValueValueStore`

func CloneValue

func CloneValue(value Value) Value

CloneValue creates a copy of value

func (Value) IsZero

func (value Value) IsZero() bool

IsZero returns true if the value struct is it's zero value

func (Value) MarshalBinary

func (value Value) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface for the Value type

type Values

type Values []Value

Values is the type for a slice of Values in a `KeyValueStore`

Directories

Path Synopsis
schema
Code generated by go-bindata.
Code generated by go-bindata.
redisserver
Package redisserver is package for starting a redis test server
Package redisserver is package for starting a redis test server

Jump to

Keyboard shortcuts

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