diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 199677f..cc03b11 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -60,7 +60,7 @@ jobs: run: | echo "## Lines of code" >> $GITHUB_STEP_SUMMARY - go install github.com/boyter/scc/v3@latest + go install github.com/boyter/scc/v3@v3.6.0 scc --format html-table . | tee -a $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e6ac920..06419e4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -40,7 +40,7 @@ jobs: run: | echo "## Lines of code" >> $GITHUB_STEP_SUMMARY - go install github.com/boyter/scc/v3@latest + go install github.com/boyter/scc/v3@v3.6.0 scc --format html-table . | tee -a $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY diff --git a/README.md b/README.md index c609055..9ae8388 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # httpretrier -[![Go Reference](https://pkg.go.dev/badge/github.com/p2p-b2b/httpretrier.svg)](https://pkg.go.dev/github.com/p2p-b2b/httpretrier) -![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/p2p-b2b/httpretrier?style=plastic) +[![Go Reference](https://pkg.go.dev/badge/github.com/slashdevops/httpretrier.svg)](https://pkg.go.dev/github.com/slashdevops/httpretrier) +![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/slashdevops/httpretrier?style=plastic) `httpretrier` is a Go library that provides a **transparent** drop-in replacement for `http.Client` with automatic retry logic. It preserves all existing request headers (including authentication) while handling transient server errors (5xx) or network issues by retrying requests based on configurable strategies. @@ -23,13 +23,13 @@ ## Installation ```bash -go get github.com/p2p-b2b/httpretrier@latest +go get github.com/slashdevops/httpretrier@latest ``` ## Update ```bash -go get -u github.com/p2p-b2b/httpretrier@latest +go get -u github.com/slashdevops/httpretrier@latest ``` ## Usage @@ -66,7 +66,7 @@ import ( "sync/atomic" "time" - "github.com/p2p-b2b/httpretrier" + "github.com/slashdevops/httpretrier" ) func main() { @@ -124,7 +124,7 @@ import ( "net/http" "time" - "github.com/p2p-b2b/httpretrier" + "github.com/slashdevops/httpretrier" ) func main() { @@ -172,7 +172,7 @@ import ( "net/http/httptest" "time" - "github.com/p2p-b2b/httpretrier" + "github.com/slashdevops/httpretrier" ) func main() { diff --git a/example_httpretrier_test.go b/example_httpretrier_test.go index 6c225ef..25c5bae 100644 --- a/example_httpretrier_test.go +++ b/example_httpretrier_test.go @@ -5,11 +5,10 @@ import ( "io" "net/http" "net/http/httptest" - "net/url" "sync/atomic" "time" - "github.com/p2p-b2b/httpretrier" + "github.com/slashdevops/httpretrier" ) // Example demonstrates using exponential backoff. @@ -42,7 +41,7 @@ func Example() { fmt.Printf("Client: Request failed: %v\n", err) return } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() body, _ := io.ReadAll(resp.Body) fmt.Printf("Client: Received response: Status=%s, Body='%s'\n", resp.Status, string(body)) @@ -82,7 +81,7 @@ func ExampleNewClient_withExistingAuth() { } else { fmt.Println("200 OK") w.WriteHeader(http.StatusOK) - w.Write([]byte("Authenticated and retried successfully")) + _, _ = w.Write([]byte("Authenticated and retried successfully")) } })) defer server.Close() @@ -100,7 +99,7 @@ func ExampleNewClient_withExistingAuth() { fmt.Printf("Client: Request failed: %v\n", err) return } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() body, _ := io.ReadAll(resp.Body) fmt.Printf("Client: Success! Status=%s, Body='%s'\n", resp.Status, string(body)) @@ -126,7 +125,7 @@ func ExampleNewClientBuilder_transparent() { fmt.Printf("Server: Received custom header: %s\n", customValue) } w.WriteHeader(http.StatusOK) - w.Write([]byte("Custom headers preserved!")) + _, _ = w.Write([]byte("Custom headers preserved!")) })) defer server.Close() @@ -148,7 +147,7 @@ func ExampleNewClientBuilder_transparent() { fmt.Printf("Client: Request failed: %v\n", err) return } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() body, _ := io.ReadAll(resp.Body) fmt.Printf("Client: Response: %s\n", string(body)) @@ -173,7 +172,7 @@ func ExampleNewClient_withCustomTransport() { w.WriteHeader(http.StatusInternalServerError) } else { w.WriteHeader(http.StatusOK) - w.Write([]byte("Custom transport with retries works!")) + _, _ = w.Write([]byte("Custom transport with retries works!")) } })) defer server.Close() @@ -200,7 +199,7 @@ func ExampleNewClient_withCustomTransport() { fmt.Printf("Client: Request failed: %v\n", err) return } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() body, _ := io.ReadAll(resp.Body) fmt.Printf("Client: Response: %s\n", string(body)) @@ -216,10 +215,3 @@ func ExampleNewClient_withCustomTransport() { } // Helper function to parse URL (avoiding error handling in example) -func mustParseURL(rawURL string) *url.URL { - u, err := url.Parse(rawURL) - if err != nil { - panic(err) - } - return u -} diff --git a/go.mod b/go.mod index 0bec9c2..4408571 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/p2p-b2b/httpretrier +module github.com/slashdevops/httpretrier -go 1.25.1 +go 1.26.4 diff --git a/httpretrier_test.go b/httpretrier_test.go index e2443f5..90bc2b9 100644 --- a/httpretrier_test.go +++ b/httpretrier_test.go @@ -120,7 +120,7 @@ func TestRetryTransport_SuccessOnFirstAttempt(t *testing.T) { if err != nil { t.Fatalf("Expected no error, got %v", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK { t.Errorf("Expected status code %d, got %d", http.StatusOK, resp.StatusCode) @@ -167,7 +167,7 @@ func TestRetryTransport_SuccessAfterRetries(t *testing.T) { if err != nil { t.Fatalf("Expected no error, got %v", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK { t.Errorf("Expected status code %d, got %d", http.StatusOK, resp.StatusCode) @@ -318,7 +318,7 @@ func TestRetryTransport_RequestBodyCloning(t *testing.T) { if err != nil { t.Fatalf("Expected no error, got %v", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK { t.Errorf("Expected status OK, got %d", resp.StatusCode) @@ -388,7 +388,7 @@ func TestRetryTransport_NilRetryStrategyUsesDefault(t *testing.T) { if err != nil { t.Fatalf("Expected no error, got %v", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() if resp.StatusCode != http.StatusOK { t.Errorf("Expected status OK, got %d", resp.StatusCode) @@ -424,7 +424,7 @@ func TestRetryTransport_NonRetryableError(t *testing.T) { if err != nil { t.Fatalf("Expected no error, got %v", err) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() // Should return immediately with the 400 status, no retries if resp.StatusCode != http.StatusBadRequest {