Documentation
¶
Overview ¶
Package eshttp contains client to the HTTP API of serverless-event-store
The client wraps the following Event Store operations:
- create event stream with initial event
- append event to stream
- get stream details
- list streams
- get stream events
To get started you need a base URL of the Event Store:
esHttpClient := eshttp.NewClient("https://****.lambda-url.****.on.aws/")
Index ¶
- type Client
- func (c *Client) AppendEvent(streamType string, streamId uuid.UUID, revision int, event estypes.NewEsEvent) (*estypes.Stream, error)
- func (c *Client) CreateStream(streamType string, initialEvent estypes.NewEsEvent) (*estypes.Stream, error)
- func (c *Client) GetEvents(streamType string, streamId uuid.UUID, afterRevision int) iter.Seq2[*estypes.Event, error]
- func (c *Client) GetStreamDetails(streamType string, streamId uuid.UUID) (*estypes.Stream, error)
- func (c *Client) GetStreams(streamType string, updatedAfter time.Time) iter.Seq2[*estypes.Stream, error]
- type Error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) AppendEvent ¶
func (c *Client) AppendEvent(streamType string, streamId uuid.UUID, revision int, event estypes.NewEsEvent) (*estypes.Stream, error)
AppendEvent persists another event at the tail of the stream.
To successfully append an event to a stream, you should not at which revision N the stream currently is. Then you can append an event exactly with revision N + 1. Attempt to append an event with inconsistent revision will cause an error.
This is one of the guarantees of an Event Store.
func (*Client) CreateStream ¶
func (c *Client) CreateStream(streamType string, initialEvent estypes.NewEsEvent) (*estypes.Stream, error)
CreateStream persists new event-sourced stream together with initial event.
Stream type means a kind of workflow that the stream will follow. Streams of the same type support the same types of events and are subject to the same processing.
When subscribing to an Event Store updates, stream type can be used as a criteria in SNS subscription filter.
func (*Client) GetEvents ¶
func (c *Client) GetEvents(streamType string, streamId uuid.UUID, afterRevision int) iter.Seq2[*estypes.Event, error]
GetEvents retrieves the stream events in order till the end.
afterRevision parameter allows to retrieve newer events after certain revision. To get all events right from the start GetEvents should be used with afterRevision = 0
The returned value is an iterator. Result pagination is handled internally, so the client will request as many pages as needed.
Use it with for...range loops:
events := esHttpClient.GetEvents("my-stream-type", streamId, 0)
for event, err := range events {
// process event
}
Or with pull processing:
events := esHttpClient.GetEvents("my-stream-type", streamId, 0)
next, stop := iter.Pull2(events)
event, err, isValid := next()
stop()