-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.go
54 lines (46 loc) · 1.17 KB
/
types.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 types
import (
"context"
"fmt"
"sync"
"github.com/go-logr/logr"
)
// EndPoint declares plugin interface
type EndPoint interface {
// Listen holds signature for Listen func which starts listening goroutine
Listen(id int, channel string, pipe chan string) error
// Notify holds signature for Notify func which starts notify goroutine
Notify(id int, channel string, pipe chan string) error
}
// EndPointAttr holds common endpoint attributes
type EndPointAttr struct {
Log logr.Logger
WG *sync.WaitGroup
Ctx context.Context
Abort chan string
}
// Printer prints pipe lines to STDOUT
func (ep EndPointAttr) Printer(log logr.Logger, pipe chan string) {
ep.WG.Add(1)
defer ep.WG.Done()
for {
select {
case line := <-pipe:
fmt.Println(line)
case <-ep.Ctx.Done():
log.V(1).Info("Endpoint close")
return
}
}
}
// NewBlankEndPointAttr creates new EndPointAttr for testing purposes
//func NewBlankEndPointAttr(ctx context.Context) EndPointAttr {
func NewBlankEndPointAttr(ctx context.Context) EndPointAttr {
var wg sync.WaitGroup
return EndPointAttr{
Log: logr.FromContextOrDiscard(ctx),
WG: &wg,
Abort: make(chan string),
Ctx: ctx,
}
}