-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
53 lines (45 loc) · 1.1 KB
/
client.go
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
package logRushClient
type Client struct {
options ClientOptions
streams map[string]Stream
}
func NewClient(options ClientOptions) Client {
return Client{
options: options,
streams: map[string]Stream{},
}
}
func (c *Client) CreateStream(name string) (Stream, error) {
stream := NewLogStream(c.options, name, "", "")
if _, ok := c.streams[stream.id]; ok {
return Stream{}, ErrStreamExists
}
c.streams[stream.id] = stream
return stream, nil
}
func (c *Client) ResumeStream(name, id, key string) (Stream, error) {
stream := NewLogStream(c.options, name, id, key)
if _, ok := c.streams[stream.id]; ok {
return Stream{}, ErrStreamExists
}
c.streams[stream.id] = stream
return stream, nil
}
func (c *Client) DeleteStream(id string, sendRemainingLogs bool) error {
stream, ok := c.streams[id]
if !ok {
return ErrStreamNotExists
}
if sendRemainingLogs {
stream.FlushLogs()
}
delete(c.streams, id)
return nil
}
func (c *Client) Disconnect(sendRemainingLogs bool) error {
var err error
for _, stream := range c.streams {
err = c.DeleteStream(stream.id, sendRemainingLogs)
}
return err
}