/
push.go
54 lines (46 loc) · 1.22 KB
/
push.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 push
// TextPusher is a type that can push text and markdown messages.
type TextPusher interface {
PushText(s string) error
PushMarkdown(title, content string) error
}
// RawPusher is a type that can push raw messages.
type RawPusher interface {
PushRaw(r *RawMessage) error
}
type multiPusher struct {
textPusher []TextPusher
rawPusher []RawPusher
}
// MultiTextPusher returns a TextPusher that pushes to all the given pushers.
func MultiTextPusher(pushers ...TextPusher) TextPusher {
return &multiPusher{textPusher: pushers}
}
// MultiRawPusher returns a RawPusher that pushes to all the given pushers.
func MultiRawPusher(pushers ...RawPusher) RawPusher {
return &multiPusher{rawPusher: pushers}
}
func (m *multiPusher) PushText(s string) error {
for _, push := range m.textPusher {
if err := push.PushText(s); err != nil {
return err
}
}
return nil
}
func (m *multiPusher) PushMarkdown(title, content string) error {
for _, push := range m.textPusher {
if err := push.PushMarkdown(title, content); err != nil {
return err
}
}
return nil
}
func (m *multiPusher) PushRaw(r *RawMessage) error {
for _, push := range m.rawPusher {
if err := push.PushRaw(r); err != nil {
return err
}
}
return nil
}