-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (41 loc) · 969 Bytes
/
main.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
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"webex-notifier/conf"
"github.com/spf13/viper"
)
func main() {
conf.ReadConf()
conf.ParseCliOpts()
type payloadStruct struct {
RoomId string `json:"roomId"`
Markdown string `json:"markdown"`
}
host := viper.GetString("webex_url")
var payload = payloadStruct{
RoomId: viper.GetString("webex_channel"),
Markdown: viper.GetString("webex_message"),
}
payloadJson, err := json.Marshal(payload)
if err != nil {
panic(err.Error())
}
req, _ := http.NewRequest("POST", host, bytes.NewBuffer(payloadJson))
if err != nil {
fmt.Print(err)
}
req.Header.Add("content-type", "application/json")
req.Header.Add("Authorization", "Bearer "+viper.GetString("webex_token"))
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err.Error())
}
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}