(path string, params url.Values)
| 48 | } |
| 49 | |
| 50 | func (client *Client) query(path string, params url.Values) ([]byte, error) { |
| 51 | u, err := url.Parse(client.BaseURL) |
| 52 | if err != nil { |
| 53 | return nil, err |
| 54 | } |
| 55 | u = u.JoinPath(path) |
| 56 | |
| 57 | u.RawQuery = params.Encode() |
| 58 | |
| 59 | req, err := http.NewRequest(http.MethodGet, u.String(), nil) |
| 60 | if err != nil { |
| 61 | return nil, err |
| 62 | } |
| 63 | req.Header.Set("Content-Type", "application/json") |
| 64 | req.Header.Set("Accept", "application/json") |
| 65 | req.Header.Set("User-Agent", build.UserAgent) |
| 66 | // #nosec G704 -- baseURL is provided by the user via CLI flags |
| 67 | response, err := client.Client.Do(req) |
| 68 | if err != nil { |
| 69 | return nil, err |
| 70 | } |
| 71 | |
| 72 | if response.StatusCode != http.StatusOK { |
| 73 | return nil, errors.New(http.StatusText(response.StatusCode)) |
| 74 | } |
| 75 | |
| 76 | defer response.Body.Close() |
| 77 | |
| 78 | body, err := io.ReadAll(response.Body) |
| 79 | if err != nil { |
| 80 | return nil, err |
| 81 | } |
| 82 | |
| 83 | return body, nil |
| 84 | } |
| 85 | |
| 86 | func (client *Client) GetPackages(packages ...string) (PackagePopularityList, error) { |
| 87 | ppl := PackagePopularityList{} |
no outgoing calls
no test coverage detected