Documentation ¶
Overview ¶
Package evt provides servers and tools for event sourcing.
Index ¶
- Constants
- func CollectAll(evs []*Event) map[Sig][]*Event
- func MergeDeltas(a, b lit.Delta) error
- func NextRev(last, rev time.Time) time.Time
- func RawSchema() string
- type Action
- type Audit
- type ByID
- type ByRev
- type Ctrl
- type Event
- type Ledger
- type LocalPublisher
- type MemLedger
- type ModelAuthority
- type MonFunc
- type MonReq
- type MonRes
- type Monitor
- type Note
- type PubFunc
- type PubReq
- type PubRes
- type Publisher
- type Replicator
- type SatFunc
- type SatReq
- type SatRes
- type Satellite
- type Server
- type Sig
- type StatFunc
- type StatRes
- type Status
- type SubFunc
- type SubReq
- type SubRes
- type Subscriber
- type Subscribers
- func (subs *Subscribers) Bcast(from hub.Conn, rev time.Time)
- func (subs *Subscribers) BcastMsg(msg *hub.Msg)
- func (subs *Subscribers) Get(id int64) *Subscriber
- func (subs *Subscribers) Mon(c hub.Conn, rev time.Time, ws []Watch) int64
- func (subs *Subscribers) Show(from hub.Conn, evs []*Event) (sub *Subscriber, trig bool)
- func (subs *Subscribers) Sub(c hub.Conn, rev time.Time, tops []string) (*Subscriber, []string)
- func (subs *Subscribers) Unmon(c hub.Conn, mon int64) bool
- func (subs *Subscribers) Unsub(c hub.Conn, tops []string) *Subscriber
- type Trans
- type UnmonFunc
- type UnmonReq
- type UnmonRes
- type UnsubFunc
- type UnsubReq
- type UnsubRes
- type Update
- type Watch
Constants ¶
const ( CmdNew = "new" CmdMod = "mod" CmdDel = "del" )
Variables ¶
This section is empty.
Functions ¶
func CollectAll ¶
func MergeDeltas ¶
Types ¶
type Action ¶
Action is an unpublished event represented by a command string and argument map. It usually is a data operation on a record identified by a topic and primary key.
type Audit ¶
type Audit struct { Rev time.Time `json:"rev"` Created time.Time `json:"created,omitempty"` Arrived time.Time `json:"arrived,omitempty"` Usr string `json:"usr,omitempty"` Extra *lit.Dict `json:"extra,omitempty"` }
Audit holds detailed information for a published revision.
type Ctrl ¶
type Ctrl struct { Ledger Input chan *hub.Msg Subs *Subscribers log.Logger // contains filtered or unexported fields }
Ctrl manages subscription updates common to both the event server and satellite.
type Ledger ¶
type Ledger interface { // Rev returns the latest event revision or the zero time. Rev() time.Time Project() *dom.Project // Events returns all events for the given topics since rev. // This methods is primarily used by the event central to manage subscribed events. // The qry package can be used for more complex event queries. Events(ctx context.Context, rev time.Time, tops ...string) ([]*Event, error) }
Ledger abstracts over the event storage. It allows to access the latest revision and query events. Ledger implementations are usually not thread-safe unless explicitly documented.
type LocalPublisher ¶
type LocalPublisher interface { Replicator LocalRev() time.Time PublishLocal(Trans) (time.Time, []*Event, error) Locals() []Trans }
LocalPublisher is a replicator that can publish events locally.
type MemLedger ¶
type MemLedger struct { Reg lit.Regs Bend *qry.MemBackend // contains filtered or unexported fields }
MemLedger implements an in-memory ledger.
func NewMemLedger ¶
NewMemLedger returns a new ledger for testing, that is backed by the memory query backend b. This ledger provides no persistence and expands only minimal effort to roll back after a failed event publish. It should only be used for testing or if these constraints are well understood. The ledger assumes sole and full control over b and converts event data to an event slice and swaps previous event values with proxies.
type ModelAuthority ¶
type Replicator ¶
Replicator is a ledger that can replicate events.
type Satellite ¶
type Satellite struct { LocalPublisher *Ctrl // contains filtered or unexported fields }
Satellite connects to a server hub, replicates events, and manages local subscriptions. Satellites can publish authoritative events locally to support offline use to some extent.
func New ¶
func New(rep LocalPublisher, cli hub.Conn, auth ModelAuthority) *Satellite
type Status ¶
type Status struct { Rev time.Time `json:"rev"` Mig string `json:"mig"` On time.Time `json:"on,omitempty"` Off time.Time `json:"off,omitempty"` }
Status holds the current ledger revision migration information.
type Subscriber ¶
type Subscribers ¶
type Subscribers struct {
// contains filtered or unexported fields
}
func NewSubscribers ¶
func NewSubscribers() *Subscribers
func (*Subscribers) Bcast ¶
func (subs *Subscribers) Bcast(from hub.Conn, rev time.Time)
Bcast sends all buffered events up to revision rev out to subscribers.
func (*Subscribers) BcastMsg ¶
func (subs *Subscribers) BcastMsg(msg *hub.Msg)
func (*Subscribers) Get ¶
func (subs *Subscribers) Get(id int64) *Subscriber
func (*Subscribers) Show ¶
func (subs *Subscribers) Show(from hub.Conn, evs []*Event) (sub *Subscriber, trig bool)
Show updates all matching subscribers with evs except for the sender itself and returns a sender subscription and an indicator whether a broadcast should be triggered. The returned sub is always usable to send a result update even if the sender was unknown.
func (*Subscribers) Sub ¶
func (subs *Subscribers) Sub(c hub.Conn, rev time.Time, tops []string) (*Subscriber, []string)
func (*Subscribers) Unsub ¶
func (subs *Subscribers) Unsub(c hub.Conn, tops []string) *Subscriber
type Trans ¶
type Trans struct { ID int64 `json:"id"` Base time.Time `json:"base"` Audit Acts []Action `json:"acts"` }
Trans is an request to publish a list of actions for a base revision.