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.