Last active
April 30, 2020 14:28
-
-
Save asim/f0326dffef2f9be34aacf8db5ac0a9e8 to your computer and use it in GitHub Desktop.
The events interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍 Ok thanks makes sense - thanks for the time & response.