Skip to content

Commit 3f45f36

Browse files
ThreeAndTwodeng00
authored andcommitted
add notify case and delete redundant code
1 parent 82a63e5 commit 3f45f36

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

notify.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package notify
22

33
import (
4+
"github.com/deng00/go-notify/pagerduty"
45
"github.com/deng00/go-notify/pushover"
56
"github.com/deng00/go-notify/slack"
67
)
78

89
type Platform string
910

1011
const (
11-
PlatformSlack Platform = "slack"
12-
PlatformPushover = "pushover"
13-
PlatformDingDing = "dingding"
12+
PlatformSlack Platform = "slack"
13+
PlatformPushover = "pushover"
14+
PlatformDingDing = "dingding"
15+
Platformpagerduty = "pagerduty"
1416
)
1517

1618
type Notify struct {
@@ -35,6 +37,8 @@ func (n *Notify) Send(msg string) error {
3537
return n.sendPushOverNotify(msg)
3638
case PlatformSlack:
3739
return n.sendSlackNotify(msg)
40+
case Platformpagerduty:
41+
return n.sendPagerdutyNotify(msg)
3842
default:
3943
panic("not supported notify platform")
4044
}
@@ -58,3 +62,11 @@ func (n *Notify) sendSlackNotify(msg string) error {
5862
err := app.Send(msg)
5963
return err
6064
}
65+
66+
func (n *Notify) sendPagerdutyNotify(msg string) error {
67+
app := pagerduty.New(pagerduty.Options{
68+
Token: n.config.Token,
69+
})
70+
err := app.Send(msg)
71+
return err
72+
}

notify_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ func TestNotify_Send(t *testing.T) {
3535
}},
3636
args{msg: "test case"},
3737
},
38+
{
39+
"test pagerduty notify",
40+
fields{config: &Config{
41+
Platform: Platform("pagerduty"),
42+
Token: os.Getenv("PAGERDUTY_TOKEN"),
43+
}},
44+
args{msg: "test pagerduty"},
45+
},
3846
}
3947
for _, tt := range tests {
4048
t.Run(tt.name, func(t *testing.T) {

pagerduty/notify_test.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)