/
consumer.go
54 lines (46 loc) · 961 Bytes
/
consumer.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
package data
import (
ui "github.com/gizak/termui/v3"
"strings"
)
type Consumer struct {
SampleChannel chan *Sample
AlertChannel chan *Alert
CommandChannel chan *Command
Alert *Alert
}
func (c *Consumer) HandleConsumeSuccess() {
if c.Alert != nil && c.Alert.Recoverable {
c.Alert = nil
}
}
func (c *Consumer) HandleConsumeFailure(title string, err error, sample *Sample) {
c.AlertChannel <- &Alert{
Title: strings.ToUpper(title),
Text: err.Error(),
Color: sample.Color,
Recoverable: true,
}
}
type Sample struct {
Label string
Value string
Color *ui.Color
}
type Alert struct {
Title string
Text string
Color *ui.Color
Recoverable bool
}
type Command struct {
Type string
Value interface{}
}
func NewConsumer() *Consumer {
return &Consumer{
SampleChannel: make(chan *Sample, 10),
AlertChannel: make(chan *Alert, 10),
CommandChannel: make(chan *Command, 10),
}
}