🚨 Latest Research:Tanstack npm Packages Compromised in Ongoing Mini Shai-Hulud Supply-Chain Attack.Learn More →
Socket
Book a DemoSign in
Socket

github.com/BufferZoneCorp/go-retryablehttp

Package Overview
Dependencies
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/BufferZoneCorp/go-retryablehttp

Source
Go Modules
Version
v0.4.0
Version published
Created
Source

go-retryablehttp

Go Version License

go-retryablehttp is an HTTP client for Go with automatic retries, configurable exponential backoff, and a simple API surface. It is designed as a compatible alternative to hashicorp/go-retryablehttp with no external dependencies.

Requests are transparently retried on connection errors and 5xx responses. The client is safe for concurrent use.

Installation

go get github.com/BufferZoneCorp/go-retryablehttp

Import path

import "github.com/BufferZoneCorp/go-retryablehttp"

Usage

Basic GET with retries

package main

import (
    "fmt"
    "io"
    "log"

    retryablehttp "github.com/BufferZoneCorp/go-retryablehttp"
)

func main() {
    client := retryablehttp.NewClient()

    resp, err := client.Get("https://api.example.com/data")
    if err != nil {
        log.Fatal(err)
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Printf("status %d: %s\n", resp.StatusCode, body)
}

Custom retry configuration

import (
    "os"
    "time"

    retryablehttp "github.com/BufferZoneCorp/go-retryablehttp"
)

client := retryablehttp.NewClient()
client.RetryMax     = 5
client.RetryWaitMin = 500 * time.Millisecond
client.RetryWaitMax = 10 * time.Second
client.Logger       = os.Stderr   // log retry attempts

POST request

import (
    "bytes"
    "encoding/json"

    retryablehttp "github.com/BufferZoneCorp/go-retryablehttp"
)

client := retryablehttp.NewClient()

payload, _ := json.Marshal(map[string]string{"event": "deploy", "env": "prod"})
resp, err := client.Post(
    "https://hooks.example.com/events",
    "application/json",
    bytes.NewReader(payload),
)

Client defaults

SettingDefault
RetryMax3
RetryWaitMin1s
RetryWaitMax30s
HTTP client timeout30s
Loggerio.Discard (silent)

API reference

Client fields

FieldTypeDescription
HTTPClient*http.ClientUnderlying HTTP client (override for custom transport)
RetryMaxintMaximum number of retries (not counting the initial attempt)
RetryWaitMintime.DurationMinimum wait between retries
RetryWaitMaxtime.DurationMaximum wait between retries
Loggerio.WriterDestination for retry log lines (os.Stderr, a logger, etc.)

Methods

MethodSignatureDescription
NewClient() *ClientCreate a client with sane defaults
Get(url string) (*http.Response, error)Retryable GET
Post(url, contentType string, body io.Reader) (*http.Response, error)Retryable POST

Retry policy

A request is retried when:

  • A network or transport error occurs (connection refused, timeout, etc.)
  • The server returns a 5xx status code

Backoff is linear by default: RetryWaitMin * attempt, capped at RetryWaitMax.

Requirements

  • Go 1.21 or later
  • No external dependencies

License

MIT — see LICENSE.

FAQs

Package last updated on 23 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts