Skip to content

Commit

Permalink
Update godoc, remove retryAfter json, go mod tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
danaelhe committed Aug 3, 2023
1 parent 32d5d94 commit f19d938
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.18

require (
github.com/google/go-querystring v1.1.0
github.com/hashicorp/go-retryablehttp v0.7.4
github.com/stretchr/testify v1.4.0
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af
Expand All @@ -13,7 +14,6 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.7.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-retryablehttp v0.7.4 h1:ZQgVdpTdAL7WpMIwLzCfbalOcSUdkDZnpUv3/+BxzFA=
github.com/hashicorp/go-retryablehttp v0.7.4/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
Expand Down
14 changes: 7 additions & 7 deletions godo.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const (
headerRateLimit = "RateLimit-Limit"
headerRateRemaining = "RateLimit-Remaining"
headerRateReset = "RateLimit-Reset"
headerRetryAfter = "Retry-After"
)

// Client manages communication with DigitalOcean V2 API.
Expand Down Expand Up @@ -104,6 +103,13 @@ type Client struct {
// requests that fail with 429 or 500-level response codes using the go-retryablehttp client.
// RetryConfig.RetryMax must be configured to enable this behavior. RetryConfig.RetryWaitMin and
// RetryConfig.RetryWaitMax are optional, with the default values being 1.0 and 30.0, respectively.
//
// You can use
//
// godo.PtrTo(1.0)
//
// to explicitly set the RetryWaitMin and RetryWaitMax values.
//
// Note: Opting to use the go-retryablehttp client will overwrite any custom HTTP client passed into New().
// Only the custom HTTP client's custom transport and timeout will be maintained.
type RetryConfig struct {
Expand Down Expand Up @@ -183,9 +189,6 @@ type Rate struct {

// The time at which the current rate limit will reset.
Reset Timestamp `json:"reset"`

// The number of seconds the client is expected to wait before making a follow-up HTTP request
RetryAfter int `json:"retry-after"`
}

func addOptions(s string, opt interface{}) (string, error) {
Expand Down Expand Up @@ -451,9 +454,6 @@ func (r *Response) populateRate() {
r.Rate.Reset = Timestamp{time.Unix(v, 0)}
}
}
if retryAfter := r.Header.Get(headerRetryAfter); retryAfter != "" {
r.Rate.RetryAfter, _ = strconv.Atoi(retryAfter)
}
}

// Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value
Expand Down
13 changes: 2 additions & 11 deletions godo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ func TestDo_rateLimit(t *testing.T) {
w.Header().Add(headerRateLimit, "60")
w.Header().Add(headerRateRemaining, "59")
w.Header().Add(headerRateReset, "1372700873")
w.Header().Add(headerRetryAfter, "23")
})

var expected int
Expand All @@ -509,9 +508,6 @@ func TestDo_rateLimit(t *testing.T) {
if expected = 0; client.Rate.Remaining != expected {
t.Errorf("Client rate remaining = %v, got %v", client.Rate.Remaining, expected)
}
if expected = 0; client.Rate.RetryAfter != expected {
t.Errorf("Client rate retry-after = %v, got %v", client.Rate.RetryAfter, expected)
}
if !client.Rate.Reset.IsZero() {
t.Errorf("Client rate reset not initialized to zero value")
}
Expand All @@ -531,9 +527,6 @@ func TestDo_rateLimit(t *testing.T) {
if expected = 59; client.Rate.Remaining != expected {
t.Errorf("Client rate remaining = %v, expected %v", client.Rate.Remaining, expected)
}
if expected = 23; client.Rate.RetryAfter != expected {
t.Errorf("Client rate retry-after = %v, expected %v", client.Rate.RetryAfter, expected)
}
reset := time.Date(2013, 7, 1, 17, 47, 53, 0, time.UTC)
if client.Rate.Reset.UTC() != reset {
t.Errorf("Client rate reset = %v, expected %v", client.Rate.Reset, reset)
Expand Down Expand Up @@ -627,11 +620,9 @@ func TestWithRetryAndBackoffs(t *testing.T) {
})

oauth_client := oauth2.NewClient(oauth2.NoContext, tokenSrc)
var waitMax *float64 = new(float64)
var waitMin *float64 = new(float64)

*waitMax = 6.0
*waitMin = 3.0
waitMax := PtrTo(6.0)
waitMin := PtrTo(3.0)

retryConfig := RetryConfig{
RetryMax: 3,
Expand Down

0 comments on commit f19d938

Please sign in to comment.