forked from credondocr/dota2api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
61 lines (49 loc) · 957 Bytes
/
utils.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 dota2api
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strconv"
)
//http get
func (api Dota2) Get(u string) ([]byte, error) {
var body []byte
request, err := http.NewRequest(http.MethodGet, u, nil)
if err != nil {
return body, err
}
resp, err := api.client.Do(request)
if err != nil {
return body, err
}
defer func() { _ = resp.Body.Close() }()
body, err = ioutil.ReadAll(resp.Body)
if err != nil {
return body, err
}
return body, nil
}
func parseUrl(u string, param map[string]interface{}) (string, error) {
ur, err := url.Parse(u)
if err != nil {
return "", err
}
q := ur.Query()
for k, v := range param {
q.Set(k, fmt.Sprintf("%v", v))
}
ur.RawQuery = q.Encode()
return ur.String(), nil
}
func ArrayIntToStr(arr []uint64) string {
var strArr string
strArr = "["
for i, v := range arr {
strArr += strconv.FormatUint(v, 10)
if i+1 < len(arr) {
strArr += ","
}
}
return strArr + "]"
}