go-retryablehttp

Go 中可重试的 HTTP 客户端。「Retryable HTTP client in Go」

  • 所有者: hashicorp/go-retryablehttp
  • 平台: Linux,Mac,Windows
  • 許可證: Mozilla Public License 2.0
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

go-retryablehttp

Build Status
Go Documentation

The retryablehttp package provides a familiar HTTP client interface with
automatic retries and exponential backoff. It is a thin wrapper over the
standard net/http client library and exposes nearly the same public API. This
makes retryablehttp very easy to drop into existing programs.

retryablehttp performs automatic retries under certain conditions. Mainly, if
an error is returned by the client (connection errors, etc.), or if a 500-range
response code is received (except 501), then a retry is invoked after a wait
period. Otherwise, the response is returned and left to the caller to
interpret.

The main difference from net/http is that requests which take a request body
(POST/PUT et. al) can have the body provided in a number of ways (some more or
less efficient) that allow "rewinding" the request body if the initial request
fails so that the full request can be attempted again. See the
godoc for more
details.

Version 0.6.0 and before are compatible with Go prior to 1.12. From 0.6.1 onward, Go 1.12+ is required.
From 0.6.7 onward, Go 1.13+ is required.

Example Use

Using this library should look almost identical to what you would do with
net/http. The most simple example of a GET request is shown below:

resp, err := retryablehttp.Get("/foo")
if err != nil {
    panic(err)
}

The returned response object is an *http.Response, the same thing you would
usually get from net/http. Had the request failed one or more times, the above
call would block and retry with exponential backoff.

Getting a stdlib *http.Client with retries

It's possible to convert a *retryablehttp.Client directly to a *http.Client.
This makes use of retryablehttp broadly applicable with minimal effort. Simply
configure a *retryablehttp.Client as you wish, and then call StandardClient():

retryClient := retryablehttp.NewClient()
retryClient.RetryMax = 10

standardClient := retryClient.StandardClient() // *http.Client

For more usage and examples see the
godoc.

主要指標

概覽
名稱與所有者hashicorp/go-retryablehttp
主編程語言Go
編程語言Makefile (語言數: 2)
平台
許可證Mozilla Public License 2.0
所有者活动
創建於2015-12-07 16:46:24
推送於2025-06-06 11:13:04
最后一次提交
發布數22
最新版本名稱v0.7.7 (發布於 )
第一版名稱v0.5.0 (發布於 )
用户参与
星數2.1k
關注者數292
派生數269
提交數229
已啟用問題?
問題數102
打開的問題數49
拉請求數80
打開的拉請求數29
關閉的拉請求數49
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?