Skip to content

Instantly share code, notes, and snippets.

@asim
Last active April 30, 2020 14:28
Show Gist options
  • Save asim/f0326dffef2f9be34aacf8db5ac0a9e8 to your computer and use it in GitHub Desktop.
Save asim/f0326dffef2f9be34aacf8db5ac0a9e8 to your computer and use it in GitHub Desktop.
The events interface
// Package events is for event streaming
package events
// Events is an event streaming interface
type Events interface {
// Stream returns a event stream by ID
Stream(id string, ...StreamOption) Stream
}
// Stream represents an event stream
type Stream interface {
// Read from the stream
Read() (*Event, error)
// Write to the stream
Write(*Event) error
}
// Event is a single event sent or received on a stream
type Event struct {
// Unique ID
Id string
// Timestamp of event
Timestamp time.Time
// Associated metadata
Header map[string]string
// Payload of the event
Body []byte
}
type StreamOptions struct {
// The offset at which to start reading from
Offset time.Time
}
type StreamOption func(*StreamOptions) error
// WithOffset sets the offset from which to read
type WithOffset(t time.Time) StreamOption {
return func(o *StreamOptions) error {
o.Offset = t
}
}
@kylehqcom
Copy link

👍 Ok thanks makes sense - thanks for the time & response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment