-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsender.go
46 lines (33 loc) · 808 Bytes
/
sender.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
package main
import (
"bytes"
"fmt"
"net/http"
"strings"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
func sendToChannel(c *cli.Context) {
var buffer bytes.Buffer
url := c.String("webhook-url")
message := &slackMessage{
Message: c.String("message"),
}
buffer.WriteString(`{ "text": "`)
buffer.WriteString(message.toString())
buffer.WriteString(`"}`)
log.Info(fmt.Sprintf("Sending message to url %s", url))
log.Info(fmt.Sprintf("Sending message %s", buffer.String()))
res, err := http.Post(url, "application/x-www-form-urlencoded", strings.NewReader(buffer.String()))
if err != nil {
log.Error(err.Error())
}
log.Info(res.Status)
log.Warn("Done")
}
func (sm slackMessage) toString() string {
return sm.Message
}
type slackMessage struct {
Message string
}