-
Notifications
You must be signed in to change notification settings - Fork 33
/
channels.go
60 lines (48 loc) · 1.75 KB
/
channels.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 mackerel
import "fmt"
// Channel represents a Mackerel notification channel.
// ref. https://mackerel.io/api-docs/entry/channels
type Channel struct {
// ID is excluded when used to call CreateChannel
ID string `json:"id,omitempty"`
Name string `json:"name"`
Type string `json:"type"`
SuspendedAt *int64 `json:"suspendedAt,omitempty"`
// Exists when the type is "email"
Emails *[]string `json:"emails,omitempty"`
UserIDs *[]string `json:"userIds,omitempty"`
// Exists when the type is "slack"
Mentions Mentions `json:"mentions,omitempty"`
// In order to support both 'not setting this field' and 'setting the field as false',
// this field needed to be *bool not bool.
EnabledGraphImage *bool `json:"enabledGraphImage,omitempty"`
// Exists when the type is "slack" or "webhook"
URL string `json:"url,omitempty"`
// Exists when the type is "email", "slack", or "webhook"
Events *[]string `json:"events,omitempty"`
}
// Mentions represents the structure used for slack channel mentions
type Mentions struct {
OK string `json:"ok,omitempty"`
Warning string `json:"warning,omitempty"`
Critical string `json:"critical,omitempty"`
}
// FindChannels finds channels.
func (c *Client) FindChannels() ([]*Channel, error) {
data, err := requestGet[struct {
Channels []*Channel `json:"channels"`
}](c, "/api/v0/channels")
if err != nil {
return nil, err
}
return data.Channels, nil
}
// CreateChannel creates a channel.
func (c *Client) CreateChannel(param *Channel) (*Channel, error) {
return requestPost[Channel](c, "/api/v0/channels", param)
}
// DeleteChannel deletes a channel.
func (c *Client) DeleteChannel(channelID string) (*Channel, error) {
path := fmt.Sprintf("/api/v0/channels/%s", channelID)
return requestDelete[Channel](c, path)
}