-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathget.go
46 lines (37 loc) · 888 Bytes
/
get.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 (
"io/ioutil"
"log"
"net/http"
)
func get(url string) []byte {
return processHTTP(http.Get(url))
}
func getGithub(url string) []byte {
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Printf("[-] Could not create HTTP request: %s\n", err.Error())
return []byte("")
}
req.Header.Set("Authorization", "token "+conf.GhToken)
resp, err := client.Do(req)
return processHTTP(resp, err)
}
func processHTTP(resp *http.Response, err error) []byte {
if err != nil {
log.Println("[-] Could not access url.")
return []byte("")
}
if resp.StatusCode != 200 {
log.Printf("[-] Received HTTP error %d.\n", resp.StatusCode)
return []byte("")
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Println("[-] Could not read response")
return []byte("")
}
return body
}