-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_watch.go
56 lines (44 loc) · 1007 Bytes
/
cmd_watch.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
54
55
56
package flowstate
import "time"
type WatchListener interface {
Listen() <-chan State
Close()
}
func Watch(labels map[string]string) *WatchCommand {
return (&WatchCommand{}).WithORLabels(labels)
}
func DoWatch(e Engine, cmd *WatchCommand) (WatchListener, error) {
if err := e.Do(cmd); err != nil {
return nil, err
}
return cmd.Listener, nil
}
type WatchCommand struct {
command
SinceRev int64
SinceLatest bool
SinceTime time.Time
Labels []map[string]string
Listener WatchListener
}
func (c *WatchCommand) WithSinceRev(rev int64) *WatchCommand {
c.SinceLatest = false
c.SinceRev = rev
return c
}
func (c *WatchCommand) WithSinceLatest() *WatchCommand {
c.SinceLatest = true
c.SinceRev = 0
return c
}
func (c *WatchCommand) WithSinceTime(since time.Time) *WatchCommand {
c.SinceTime = since
return c
}
func (c *WatchCommand) WithORLabels(labels map[string]string) *WatchCommand {
if len(labels) == 0 {
return c
}
c.Labels = append(c.Labels, labels)
return c
}