-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.go
More file actions
73 lines (59 loc) · 1.89 KB
/
client.go
File metadata and controls
73 lines (59 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package goro
import (
"net/http"
"github.com/dghubble/sling"
)
// Client is a connection to an event store
type Client struct {
sling *sling.Sling
}
// ClientOption applies options to a client
type ClientOption func(*Client)
// WithBasicAuth adds basic authentication to the Event Store
func WithBasicAuth(username, password string) ClientOption {
return func(c *Client) {
c.sling.SetBasicAuth(username, password)
}
}
// WithHTTPClient sets the http.Client for the Client
func WithHTTPClient(httpClient *http.Client) ClientOption {
return func(c *Client) {
c.sling.Client(httpClient)
}
}
// Connect creates a new client
func Connect(host string, options ...ClientOption) *Client {
c := &Client{
sling: sling.New().Base(host),
}
for _, opt := range options {
opt(c)
}
return c
}
// Sling creates a new Sling object
func (c Client) Sling() *sling.Sling {
return c.sling.New()
}
// Writer creates a new Writer for a stream
func (c Client) Writer(stream string) Writer {
return NewWriter(c, stream)
}
// BackwardsReader creates a new Reader that reads backwards on a stream
func (c Client) BackwardsReader(stream string) Reader {
return NewBackwardsReader(c, stream)
}
// FowardsReader creates a new Reader that reads forwards on a stream
func (c Client) FowardsReader(stream string) Reader {
return NewForwardsReader(c, stream)
}
// CatchupSubscription creates a new catchup style subscription that
// starts reading at an event number and continues forwards
func (c Client) CatchupSubscription(stream string, start int64) Subscriber {
return NewCatchupSubscription(c, stream, start)
}
// PersistentSubscription creates a new competing consumer style subscription
// with the given settings
func (c Client) PersistentSubscription(stream, subscriptionName string, settings PersistentSubscriptionSettings) (Subscriber, error) {
return NewPersistentSubscription(c, stream, subscriptionName, settings)
}