forked from OpenAyame/ayame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhook.go
More file actions
46 lines (39 loc) · 938 Bytes
/
Copy pathwebhook.go
File metadata and controls
46 lines (39 loc) · 938 Bytes
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"
"encoding/json"
"net/http"
"time"
)
type httpResponse struct {
Status string `json:"status"`
Proto string `json:"proto"`
Header http.Header `json:"header"`
Body string `json:"body"`
}
// JSON HTTP Request をするだけのラッパー
func (c *connection) postRequest(u string, body interface{}) (*http.Response, error) {
reqJSON, err := json.Marshal(body)
if err != nil {
return nil, err
}
req, err := http.NewRequest(
"POST",
u,
bytes.NewBuffer([]byte(reqJSON)),
)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
timeout := time.Duration(config.WebhookRequestTimeoutSec) * time.Second
client := &http.Client{Timeout: timeout}
return client.Do(req)
}
func (c *connection) webhookLog(n string, v interface{}) {
webhookLogger.Log().
Str("roomId", c.roomID).
Str("clientId", c.ID).
Interface(n, v).
Msg("")
}