event

package
v1.3.17 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2022 License: Apache-2.0 Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMismatchEvent = errors.New("mismatched event")

Functions

This section is empty.

Types

type Base

type Base struct {
	EventName    string `json:"name"`
	EventVersion int    `json:"version"`
	BlockHeight  int64  `json:"height"`
	EventUUID    string `json:"uuid"`
}

Base is a JSON-compatible rdbprojectionbase event with sequence and EventUUID support. It is not a must to use this as rdbprojectionbase event but to implement your own one rdbprojectionbase on your design

func NewBase

func NewBase(params BaseParams) Base

func (*Base) Height

func (event *Base) Height() int64

func (*Base) Name

func (event *Base) Name() string

func (*Base) UUID

func (event *Base) UUID() string

func (*Base) Version

func (event *Base) Version() int

type BaseParams

type BaseParams struct {
	Name        string
	Version     int
	BlockHeight int64
}

type Decoder

type Decoder = func([]byte) (Event, error)

type Event

type Event interface {
	Height() int64

	Name() string
	Version() int

	// UUID returns the unique ID that is assigned on event creation
	UUID() string

	// ToJSON encodes the event into JSON string payload
	ToJSON() (string, error)

	// String function returns the stringified event
	String() string
}

Event must be JSON-completed. i.e. All important fields must be encoded to JSON

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) DecodeByType

func (registry *Registry) DecodeByType(eventName string, eventVersion int, encoded []byte) (Event, error)

func (*Registry) IsRegistered

func (registry *Registry) IsRegistered(eventName string, eventVersion int) bool

IsRegister returns true when the event to decoder mapping is already registered

func (*Registry) Register

func (registry *Registry) Register(eventName string, eventVersion int, decoder Decoder)

Register add a mapping of "event name ane version" to Decoder to the registry. It will overwrite existing registration if any.

type Store

type Store interface {
	// GetLatestEventHeight returns latest event height, nil if no event is stored
	GetLatestHeight() (*int64, error)

	GetAllByHeight(height int64) ([]Event, error)

	Insert(evt Event) error

	// InsertAll insert all events into store. It will rollback when the insert fails at any point.
	InsertAll(evt []Event) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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