From 8cfe3457214646eda636fdae827924b2704a2d02 Mon Sep 17 00:00:00 2001 From: danaelhe <42972711+danaelhe@users.noreply.github.com> Date: Mon, 14 Aug 2023 16:10:40 -0400 Subject: [PATCH] Update README.md with Retryable Info (#624) * Update README.md with Retryable Info * Update README.md * Update README.md * Apply suggestions from code review Co-authored-by: Ben Tranter --------- Co-authored-by: Ben Tranter --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 4c9ee2d7..fd3cdbd5 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,31 @@ func ListRepositoriesV2(ctx context.Context, client *godo.Client, registryName s } ``` +### Automatic Retries and Exponential Backoff + +The Godo client can be configured to use automatic retries and exponentional backoff for requests that fail with 429 or 500-level response codes via [go-retryablehttp](https://github.com/hashicorp/go-retryablehttp). To configure Godo to enable usage of go-retryablehttp, the `RetryConfig.RetryMax` must be set. + +```go +tokenSrc := oauth2.StaticTokenSource(&oauth2.Token{ + AccessToken: "dop_v1_xxxxxx", +}) + +oauth_client := oauth2.NewClient(oauth2.NoContext, tokenSrc) + +waitMax := godo.PtrTo(6.0) +waitMin := godo.PtrTo(3.0) + +retryConfig := godo.RetryConfig{ + RetryMax: 3, + RetryWaitMin: waitMin, + RetryWaitMax: waitMax, +} + +client, err := godo.New(oauth_client, godo.WithRetryAndBackoffs(retryConfig)) +``` + +Please refer to the [RetryConfig Godo documentation](https://pkg.go.dev/github.com/digitalocean/godo#RetryConfig) for more information. + ## Versioning Each version of the client is tagged and the version is updated accordingly.