sampler-fork/data/consumer.go

55 lines
961 B
Go
Raw Permalink Normal View History

2019-01-31 00:02:38 +00:00
package data
import (
ui "github.com/gizak/termui/v3"
"strings"
)
2019-03-13 03:15:55 +00:00
2019-03-08 04:04:46 +00:00
type Consumer struct {
2019-03-16 23:59:28 +00:00
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,
}
2019-02-03 03:30:45 +00:00
}
type Sample struct {
Label string
Value string
2019-03-13 03:15:55 +00:00
Color *ui.Color
2019-03-08 04:04:46 +00:00
}
type Alert struct {
Title string
Text string
Color *ui.Color
Recoverable bool
2019-03-08 04:04:46 +00:00
}
type Command struct {
Type string
Value interface{}
}
2019-03-16 23:59:28 +00:00
func NewConsumer() *Consumer {
return &Consumer{
SampleChannel: make(chan *Sample, 10),
AlertChannel: make(chan *Alert, 10),
CommandChannel: make(chan *Command, 10),
2019-03-08 04:04:46 +00:00
}
2019-01-31 00:02:38 +00:00
}