Documentation
¶
Overview ¶
Package microblob implements a thin layer above LevelDB to implement a key-value store.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidValue = errors.New("invalid entry")
ErrInvalidValue if a value is corrupted.
Functions ¶
Types ¶
type Backend ¶
type Backend interface { Get(key string) ([]byte, error) WriteEntries(entries []Entry) error Close() error }
Backend abstracts various implementations.
type BlobHandler ¶
type BlobHandler struct {
Backend Backend
}
BlobHandler serves blobs.
func (*BlobHandler) ServeHTTP ¶
func (h *BlobHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP serves HTTP.
type DebugBackend ¶
DebugBackend just writes the key, value and offsets to a given writer.
func (DebugBackend) Get ¶
func (b DebugBackend) Get(key string) ([]byte, error)
Get is a noop, always return nothing.
func (DebugBackend) WriteEntries ¶
func (b DebugBackend) WriteEntries(entries []Entry) error
WriteEntries write entries as TSV to the given writer.
type EntryWriter ¶
EntryWriter writes entries to some storage, e.g. a file or a database.
type KeyExtractor ¶
KeyExtractor extracts a string key from data.
type LevelDBBackend ¶
type LevelDBBackend struct { Blobfile string Filename string sync.Mutex // contains filtered or unexported fields }
LevelDBBackend writes entries into LevelDB.
func (*LevelDBBackend) Close ¶
func (b *LevelDBBackend) Close() error
Close closes database handle and blob file.
func (*LevelDBBackend) Get ¶
func (b *LevelDBBackend) Get(key string) (data []byte, err error)
Get retrieves the data for a given key.
func (*LevelDBBackend) WriteEntries ¶
func (b *LevelDBBackend) WriteEntries(entries []Entry) error
WriteEntries writes entries as batch into LevelDB. The value is fixed 16 byte slice, first 8 bytes represents the offset, last 8 bytes the length. https://play.golang.org/p/xwX8BmWtVl
type LineProcessor ¶
type LineProcessor struct { BatchSize int // number of lines in a batch InitialOffset int64 // allow offsets beside zero // contains filtered or unexported fields }
LineProcessor reads a line, extracts the key and writes entries.
func NewLineProcessor ¶
func NewLineProcessor(r io.Reader, w EntryWriter, f KeyFunc) LineProcessor
NewLineProcessor reads lines from the given reader, extracts the key with the given key function and writes entries to the given entry writer.
func NewLineProcessorBatchSize ¶
func NewLineProcessorBatchSize(r io.Reader, w EntryWriter, f KeyFunc, size int) LineProcessor
NewLineProcessorBatchSize reads lines from the given reader, extracts the key with the given key function and writes entries to the given entry writer. Additionally, the number of lines per batch can be specified.
func (LineProcessor) Run ¶
func (p LineProcessor) Run() error
Run starts processing the input, sequential version. TODO(miku): Remove, since this is not used anymore.
func (LineProcessor) RunWithWorkers ¶
func (p LineProcessor) RunWithWorkers() error
RunWithWorkers start processing the input, uses multiple workers.
type ParsingExtractor ¶
type ParsingExtractor struct {
Key string
}
ParsingExtractor actually parses the JSON and extracts a top-level key at the given path. This is slower than for example regular expressions, but not too much.
func (ParsingExtractor) ExtractKey ¶
func (e ParsingExtractor) ExtractKey(b []byte) (s string, err error)
ExtractKey extracts the key. Fails, if key cannot be found in the document.
type RegexpExtractor ¶
RegexpExtractor extract a key via regular expression.
func (RegexpExtractor) ExtractKey ¶
func (e RegexpExtractor) ExtractKey(b []byte) (string, error)
ExtractKey returns the key found in a byte slice. Never fails, just might return unexpected values.