Use global HTTP client whenever applicable (#2682)

This commit is contained in:
Harshavardhana
2023-02-27 17:19:56 -08:00
committed by GitHub
parent 372852ee86
commit dd913decc6
9 changed files with 40 additions and 58 deletions

View File

@@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"time"
"github.com/go-openapi/runtime/middleware"
@@ -78,20 +79,23 @@ func getReleaseServiceURL() string {
return fmt.Sprintf("%s/releases", host)
}
func getReleases(url, repo, currentRelease, search, filter string) (*models.ReleaseListResponse, error) {
func getReleases(endpoint, repo, currentRelease, search, filter string) (*models.ReleaseListResponse, error) {
rl := &models.ReleaseListResponse{}
client := &http.Client{Timeout: time.Second * 5}
req, err := http.NewRequest("GET", url, nil)
q := req.URL.Query()
q.Add("repo", repo)
q.Add("current", currentRelease)
q.Add("search", search)
q.Add("filter", filter)
req.URL.RawQuery = q.Encode()
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
if err != nil {
return nil, err
}
q := &url.Values{}
q.Add("repo", repo)
q.Add("search", search)
q.Add("filter", filter)
q.Add("current", currentRelease)
req.URL.RawQuery = q.Encode()
req.Header.Set("Content-Type", "application/json")
client := GetConsoleHTTPClient("")
client.Timeout = time.Second * 5
resp, err := client.Do(req)
if err != nil {
return nil, err