-
Notifications
You must be signed in to change notification settings - Fork 51
/
model_notification.go
60 lines (56 loc) · 1.4 KB
/
model_notification.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
55
56
57
58
59
60
package notification
import (
"encoding/json"
"fmt"
)
// Notification properties for an alert sent to the team
type Notification struct {
Type string
Value interface{}
}
func (n *Notification) UnmarshalJSON(data []byte) error {
var typ struct {
Type string `json:"type"`
}
if err := json.Unmarshal(data, &typ); err != nil {
return err
}
n.Type = typ.Type
switch typ.Type {
case "AmazonEventBridge":
n.Value = &AmazonEventBrigeNotification{}
case "BigPanda":
n.Value = &BigPandaNotification{}
case "Email":
n.Value = &EmailNotification{}
case "Jira":
n.Value = &JiraNotification{}
case "Office365":
n.Value = &Office365Notification{}
case "Opsgenie":
n.Value = &OpsgenieNotification{}
case "PagerDuty":
n.Value = &PagerDutyNotification{}
case "ServiceNow":
n.Value = &ServiceNowNotification{}
case "Slack":
n.Value = &SlackNotification{}
case "Team":
n.Value = &TeamNotification{}
case "TeamEmail":
n.Value = &TeamEmailNotification{}
case "VictorOps":
n.Value = &VictorOpsNotification{}
case "Webhook":
n.Value = &WebhookNotification{}
case "XMatters":
n.Value = &XMattersNotification{}
default:
return fmt.Errorf("Unknown notification type %v", typ.Type)
}
return json.Unmarshal(data, n.Value)
}
// MarshalJSON unwraps the `Value` and makes this marshal in the way we expect.
func (n *Notification) MarshalJSON() ([]byte, error) {
return json.Marshal(n.Value)
}