-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.go
61 lines (49 loc) · 1.12 KB
/
helpers.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
55
56
57
58
59
60
61
package harvest
import (
"io"
"net/http"
"net/url"
"github.com/google/go-querystring/query"
)
func addParamsToURL(baseURL string, opt interface{}) (string, error) {
parsedUrl, err := url.Parse(baseURL)
if err != nil {
return baseURL, err
}
values, err := query.Values(opt)
if err != nil {
return baseURL, err
}
parsedUrl.RawQuery = values.Encode()
return parsedUrl.String(), nil
}
func (h *Harvest) getURL(url string) ([]byte, error) {
Client := &http.Client{}
req, _ := http.NewRequest("GET", url, nil)
req.Header.Set("User-Agent", "Harvest Slack Bot")
req.Header.Set("Harvest-Account-ID", h.API.AccountID)
req.Header.Set("Authorization", "Bearer "+h.API.AuthToken)
req.Header.Set("Content-Type", "application/json")
resp, err := Client.Do(req)
if err != nil {
return nil, err
}
body, err := io.ReadAll(resp.Body)
defer func() {
closeErr := resp.Body.Close()
if closeErr != nil {
if err == nil {
err = closeErr
}
}
}()
return body, err
}
func containsInt(intArray []int64, intSingle int64) bool {
for _, a := range intArray {
if a == intSingle {
return true
}
}
return false
}