events

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2021 License: MIT Imports: 1 Imported by: 7

Documentation

Overview

Package events provides an event log.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Direction

type Direction string

Direction is ascending or descending.

const (
	// Ascending direction.
	Ascending Direction = "asc"
	// Descending direction.
	Descending Direction = "desc"
)

type Document added in v0.1.22

type Document map[string]interface{}

type Event

type Event struct {
	Document map[string]interface{} `json:"doc" msgpack:"doc" firestore:"doc"`

	// Index for event (read only).
	Index int64 `json:"idx" msgpack:"idx" firestore:"idx"`
	// Timestamp (read only). The time at which the event was created.
	// Firestore sets this to the document create time.
	Timestamp int64 `json:"ts" msgpack:"ts" firestore:"-"`
}

Event in an event log. If this format changes, you should also change in firestore and other backends that don't directly use this struct on set.

func (Event) Data

func (e Event) Data() []byte

type Events

type Events interface {
	// EventAdd adds (appends) event to the log.
	EventAdd(ctx context.Context, path string, d Document) (int64, error)

	// EventsAdd adds (appends) events (in a batch if multiple) to the log.
	EventsAdd(ctx context.Context, path string, d []Document) (int64, error)

	// Events retrives events from log with the specified options.
	Events(ctx context.Context, path string, opt ...Option) (Iterator, error)

	// EventsDelete deletes all events at the specified path.
	EventsDelete(ctx context.Context, path string) (bool, error)

	// EventPosition returns current position of event logs at the specified path.
	EventPosition(ctx context.Context, path string) (*Position, error)

	// EventPositions returns current positions of event logs at the specified paths.
	EventPositions(ctx context.Context, paths []string) (map[string]*Position, error)

	// Increment document name at path n amount.
	// Returns the new value and the start of the index.
	Increment(ctx context.Context, path string, name string, n int64) (int64, int64, error)
}

Events describes an append only event log.

type Iterator

type Iterator interface {
	// Next document, or nil.
	Next() (*Event, error)
	// Release resources associated with the iterator.
	Release()
}

Iterator is an iterator for Event's.

func NewIterator

func NewIterator(events []*Event) Iterator

NewIterator returns an iterator for a Event slice.

type Option

type Option func(*Options)

Option ...

func Index

func Index(i int64) Option

Index option.

func Limit

func Limit(l int64) Option

Limit option.

func WithDirection

func WithDirection(d Direction) Option

WithDirection option.

type Options

type Options struct {
	// Index to start at.
	Index int64
	// Limit is number of documents (max) to return.
	Limit int64
	// Direction to list.
	Direction Direction
}

Options ...

func NewOptions

func NewOptions(opts ...Option) Options

NewOptions parses Options.

type Position

type Position struct {
	Path      string `json:"path" msgpack:"path"`
	Index     int64  `json:"idx" msgpack:"idx"`
	Timestamp int64  `json:"ts" msgpack:"ts"`
}

Position describes a position in an event log.

Jump to

Keyboard shortcuts

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