record

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2019 License: Apache-2.0 Imports: 14 Imported by: 16

Documentation

Overview

Package record provides funcitonality for sequential storage of types in a variety of serialization formats.

Index

Constants

View Source
const (
	Unknown = Kind_Unknown
	None    = Kind_None
	Proto   = Kind_Proto
	Text    = Kind_Text
	JSON    = Kind_JSON
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FileShelf

type FileShelf struct {

	// Kind specifies the default ledger storage for new ledgers that are created.
	// It has no impact on existing ledgers.
	Kind Kind
	// contains filtered or unexported fields
}

FileShelf is an implementation of Shelf that stores it's ledgers in files. Each ledger goes in it's own files, and records are appended to the file as they arrive. The actual storage format depends on the Kind of the ledger, which is detected on open.

func (*FileShelf) Create

func (s *FileShelf) Create(ctx context.Context, name string, null interface{}) (Ledger, error)

Create implements Shelf.Create for a file backed shelf, creating a new ledger file of the current default kind. It will return an error if for any reason the ledger cannot be created.

func (*FileShelf) Open

func (s *FileShelf) Open(ctx context.Context, name string, null interface{}) (Ledger, error)

Open implements Shelf.Open for a file backed shelf. It will attempt to open and read the specified ledger, returning an error only if the ledger exists but is invalid. It will try all known ledger types in priority order, if you have more than one type for the ledger, only the first file will be found.

type Ledger

type Ledger interface {
	// Read will read all records already in the ledger and feed them to the supplied writer.
	Read(ctx context.Context, handler event.Handler) error
	// Watch will feed new entries as they arrive into the supplied handler.
	Watch(ctx context.Context, handler event.Handler)
	// Add a new entry to the ledger.
	// The record must be of the same type that the ledger was opened with.
	Add(ctx context.Context, record interface{}) error
	// Close is called to close the register, and notify all watchers.
	Close(ctx context.Context)
	// New returns a new record of the type the ledger stores.
	New(ctx context.Context) interface{}
}

Ledger is the interface to a sequential immutable record store. New records can only be added to a ledger, and old records cannot be modified.

func NewLedger

func NewLedger(ctx context.Context, instance LedgerInstance) Ledger

NewLedger returns a ledger from a backing store.

type LedgerInstance

type LedgerInstance interface {
	Write(ctx context.Context, event interface{}) error
	Reader(ctx context.Context) event.Source
	New(ctx context.Context) interface{}
	Close(ctx context.Context)
}

LedgerInstance is the interface to an implementation support class for a ledger. It is responsible for reading and writing the backing store.

type Library

type Library interface {
	// Add appends new shelves to the library.
	Add(ctx context.Context, shelf ...Shelf)
	// Open opens a ledger from a shelf in the library.
	Open(ctx context.Context, name string, null interface{}) (Ledger, error)
}

Library is the main interface to record storage. It manages a set of shelves, and uses them to open and create ledgers.

func NewLibrary

func NewLibrary(ctx context.Context) Library

NewLibrary returns a new record library.

type Shelf

type Shelf interface {
	// Open is used to open a ledger by name.
	// All records in the ledger must be of the same type as the null value.
	Open(ctx context.Context, name string, null interface{}) (Ledger, error)
	// Create is used to make and return a new ledger in the shelf.
	// All records in the ledger must be of the same type as the null value.
	Create(ctx context.Context, name string, null interface{}) (Ledger, error)
}

Shelf is the interface to an object that maintains a set of ledgers stored in a consistent way.

func NewFileShelf

func NewFileShelf(ctx context.Context, path file.Path) (Shelf, error)

NewFileShelf build a new FileShelf backed implementation of a Shelf where the files will be stored in the specified path.

func NewNullShelf

func NewNullShelf(ctx context.Context) (Shelf, error)

func NewShelf

func NewShelf(ctx context.Context, shelfURL *url.URL) (Shelf, error)

NewShelf returns a new record shelf from the supplied url. The type of shelf will depend on the url given.

Jump to

Keyboard shortcuts

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