-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
60 lines (49 loc) · 1.02 KB
/
util.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
package steamcommunityapi
import (
"io"
"net/http"
"net/url"
)
func filterOutBasedOnStatusCode(resp *http.Response) ([]byte, error) {
statusCode := resp.StatusCode
body, err := io.ReadAll(resp.Body)
if err != nil {
return []byte{}, err
}
switch statusCode {
case 200:
return body, nil
case 429:
return body, SteamRateLimitExceeded
}
// TODO: add a logger to log unexpected responses
return body, UnexpectedSteamStatusCode
}
func constructPath(path string) (url.URL, error) {
newUrl, err := url.Parse(BaseWebApiUrl)
if err != nil {
return url.URL{}, err
}
newUrl.Path = path
return *newUrl, nil
}
// since URL.Query().Encode() returns the query in a random order, have to create
// a custom function
func constructQuery(params []string) string {
query := ""
for i, v := range params {
if i == 0 {
query += v
continue
}
query += "&" + v
}
return query
}
func runHttp(url string) (*http.Response, error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
}
return resp, nil
}