-
Notifications
You must be signed in to change notification settings - Fork 29
/
report-post.go
50 lines (43 loc) · 1.32 KB
/
report-post.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
package main
import (
"encoding/json"
"fmt"
"log"
"github.com/parnurzeal/gorequest"
)
// SlackSend send the payload to then Slack Channel
func SlackSend(webhookURL string, payload *SlackPayload) []error {
data, err := json.Marshal(*payload)
if err != nil {
return []error{fmt.Errorf("marshal payload error. Status:%s", err.Error())}
}
request := gorequest.New()
resp, _, errs := request.Post(webhookURL).Send(string(data)).End()
if errs != nil {
return errs
}
if resp.StatusCode >= 400 {
log.Println(resp.StatusCode, " payload:", string(data))
return []error{fmt.Errorf("slack sending msg. Status: %v", resp.Status)}
}
log.Println("Slack send successfully! =>", webhookURL)
return nil
}
// DiscordSend send the payload to discord channel by webhook
func DiscordSend(webhookURL string, payload *DiscordPayload) []error {
data, err := json.Marshal(*payload)
if err != nil {
return []error{fmt.Errorf("marshal payload error. Status:%s", err.Error())}
}
request := gorequest.New()
resp, _, errs := request.Post(webhookURL).Send(string(data)).End()
if errs != nil {
return errs
}
if resp.StatusCode >= 400 {
log.Println(resp.StatusCode, " payload:", string(data))
return []error{fmt.Errorf("Discord sending msg. Status: %v", resp.Status)}
}
log.Println("Discord send successfully! =>", webhookURL)
return nil
}