-
Notifications
You must be signed in to change notification settings - Fork 14
/
utility_drop.go
47 lines (36 loc) · 974 Bytes
/
utility_drop.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
package transform
import (
"context"
"encoding/json"
"fmt"
"github.com/brexhq/substation/config"
iconfig "github.com/brexhq/substation/internal/config"
"github.com/brexhq/substation/message"
)
type utilityDropConfig struct{}
func (c *utilityDropConfig) Decode(in interface{}) error {
return iconfig.Decode(in, c)
}
func newUtilityDrop(_ context.Context, cfg config.Config) (*utilityDrop, error) {
conf := utilityDropConfig{}
if err := iconfig.Decode(cfg.Settings, &conf); err != nil {
return nil, fmt.Errorf("transform: utility_drop: %v", err)
}
tf := utilityDrop{
conf: conf,
}
return &tf, nil
}
type utilityDrop struct {
conf utilityDropConfig
}
func (tf *utilityDrop) Transform(ctx context.Context, msg *message.Message) ([]*message.Message, error) {
if msg.IsControl() {
return []*message.Message{msg}, nil
}
return []*message.Message{}, nil
}
func (tf *utilityDrop) String() string {
b, _ := json.Marshal(tf.conf)
return string(b)
}