Skip to content

Commit 71521ba

Browse files
refactor: route codacy-client, tools, download through httpclient (OD-30)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0526cf8 commit 71521ba

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

codacy-client/client.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package codacyclient
22

33
import (
44
"codacy/cli-v2/domain"
5+
"codacy/cli-v2/utils/httpclient"
56
"encoding/json"
67
"fmt"
78
"io"
@@ -16,8 +17,9 @@ const timeout = 10 * time.Second
1617
var CodacyApiBase = "https://app.codacy.com"
1718

1819
func getRequest(url string, apiToken string) ([]byte, error) {
19-
client := &http.Client{
20-
Timeout: timeout,
20+
client, err := httpclient.New(httpclient.WithTimeout(timeout))
21+
if err != nil {
22+
return nil, fmt.Errorf("failed to create http client: %w", err)
2123
}
2224

2325
req, err := http.NewRequest("GET", url, nil)

tools/patterns.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tools
22

33
import (
44
"codacy/cli-v2/domain"
5+
"codacy/cli-v2/utils/httpclient"
56
"encoding/json"
67
"fmt"
78
"io"
@@ -11,8 +12,9 @@ import (
1112

1213
// FetchDefaultEnabledPatterns fetches default patterns from Codacy API for a given tool UUID
1314
func FetchDefaultEnabledPatterns(toolUUID string) ([]domain.PatternDefinition, error) {
14-
client := &http.Client{
15-
Timeout: 10 * time.Second,
15+
client, err := httpclient.New(httpclient.WithTimeout(10 * time.Second))
16+
if err != nil {
17+
return nil, fmt.Errorf("failed to create http client: %w", err)
1618
}
1719

1820
// Fetch default patterns from Codacy API

utils/download.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package utils
22

33
import (
4+
"codacy/cli-v2/utils/httpclient"
45
"codacy/cli-v2/utils/logger"
56
"fmt"
67
"io"
@@ -47,7 +48,10 @@ func DownloadFile(url string, destDir string) (string, error) {
4748
logger.Debug("Making HTTP GET request", logrus.Fields{
4849
"url": url,
4950
})
50-
client := &http.Client{}
51+
client, err := httpclient.New(httpclient.WithTimeout(0)) // no timeout: large binaries
52+
if err != nil {
53+
return "", fmt.Errorf("failed to create http client: %w", err)
54+
}
5155
req, err := http.NewRequest("GET", url, nil)
5256
if err != nil {
5357
return "", fmt.Errorf("failed to create request: %w", err)

0 commit comments

Comments
 (0)