-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsight.go
More file actions
41 lines (36 loc) · 812 Bytes
/
insight.go
File metadata and controls
41 lines (36 loc) · 812 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
package insight
import (
"bytes"
"io/ioutil"
"net/http"
"time"
)
type insight struct {
Endpoint string
Timeout int
ch chan struct{}
}
// New insight pointer will query your insight API, requires insight /api endpoint
func New(endpoint string) *insight {
i := new(insight)
i.ch = make(chan struct{}, 1)
i.Endpoint = endpoint
return i
}
func (i *insight) SetThreads(amount int) {
i.ch = make(chan struct{}, amount)
}
func httpMethod(url string, data []byte) ([]byte, error) {
req, err := http.NewRequest("GET", url, bytes.NewBuffer(data))
if err != nil {
return nil, err
}
httpClient := &http.Client{Timeout: 120 * time.Second}
resp, err := httpClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
return body, err
}