-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.go
60 lines (57 loc) · 1.15 KB
/
notify.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 main
import (
"bytes"
"mime/multipart"
"net/http"
"strings"
)
func postForm(uri string, params map[string]string, files map[string][]byte) (err error) {
body := &bytes.Buffer{}
w := multipart.NewWriter(body)
for field, value := range params {
err = w.WriteField(field, value)
if err != nil {
return
}
}
for name, data := range files {
part, er := w.CreateFormFile(name, "rep.html")
if er != nil {
err = er
return er
}
_, er = part.Write(data)
if er != nil {
err = er
return
}
}
if err = w.Close(); err != nil {
return
}
req, err := http.NewRequest("POST", uri, body)
if err != nil {
return
}
req.Header.Set("Content-Type", w.FormDataContentType())
var client http.Client
res, err := client.Do(req)
if err != nil {
return
}
defer res.Body.Close()
//io.Copy(os.Stderr, res.Body)
return
}
func sendNotify(msg string, data []byte, users ...string) (err error) {
params := map[string]string{
"username": users[0], // for temp use
"message": msg,
"notify": strings.Join(users, ","),
}
files := map[string][]byte{
"file": data,
}
err = postForm("http://10.48.57.33:8080", params, files)
return
}