-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.go
50 lines (39 loc) · 958 Bytes
/
http.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"
"github.com/labstack/gommon/log"
"io/ioutil"
"net/http"
"strings"
"time"
)
func (s *Shard) GatewayBot() (st *GatewayBotResponse, err error) {
client := &http.Client{Timeout: time.Second * 10}
req, err := http.NewRequest("GET", APIBase+"/gateway/bot", nil)
req.Header.Set("Authorization", "Bot "+s.Token)
response, err := client.Do(req)
if err != nil {
log.Fatal("Error getting Gateway data: ", err)
return
}
defer func() {
err := response.Body.Close()
if err != nil {
return
}
}()
body, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatal("error reading gateway response body ", err)
}
err = json.Unmarshal(body, &st)
if err != nil {
return
}
// Ensure the gateway always has a trailing slash.
// MacOS will fail to connect if we add query params without a trailing slash on the base domain.
if !strings.HasSuffix(st.URL, "/") {
st.URL += "/"
}
return
}