From d1db35325e654642ea760d12e4c54723602f0991 Mon Sep 17 00:00:00 2001 From: James Pond Date: Tue, 30 Jan 2024 12:46:12 -0300 Subject: [PATCH] Remove unnecessary ctx from internal do function Signed-off-by: James Pond --- aws.go | 14 +++++++------- azure.go | 10 +++++----- blueprint.go | 14 +++++++------- client.go | 7 ++----- client_internal_test.go | 2 +- user.go | 2 +- 6 files changed, 23 insertions(+), 26 deletions(-) diff --git a/aws.go b/aws.go index 99eadbb..b39f2c8 100644 --- a/aws.go +++ b/aws.go @@ -99,7 +99,7 @@ func (s *AWSService) List(ctx context.Context) ([]*AWSAccount, *Response, error) return nil, nil, fmt.Errorf("%w", err) } - resp, err := s.client.do(ctx, req) + resp, err := s.client.do(req) if err != nil { return nil, resp, fmt.Errorf("%w", err) } @@ -159,7 +159,7 @@ func (s *AWSService) Create(ctx context.Context, account *AWSAccount) (*AWSAccou return nil, nil, fmt.Errorf("%w", err) } - resp, err := s.client.do(ctx, req) + resp, err := s.client.do(req) if err != nil { return nil, resp, fmt.Errorf("%w", err) } @@ -220,7 +220,7 @@ func (s *AWSService) Update(ctx context.Context, account *AWSAccount) (*Response return nil, fmt.Errorf("%w", err) } - resp, err := s.client.do(ctx, req) + resp, err := s.client.do(req) if err != nil { return resp, fmt.Errorf("%w", err) } @@ -259,7 +259,7 @@ func (s *AWSService) Delete(ctx context.Context, id string) (*Response, error) { return nil, fmt.Errorf("%w", err) } - resp, err := s.client.do(ctx, req) + resp, err := s.client.do(req) if err != nil { return resp, fmt.Errorf("%w", err) } @@ -329,7 +329,7 @@ func (s *AWSService) Snapshot( return nil, nil, fmt.Errorf("%w", err) } - resp, err := s.client.do(ctx, req) + resp, err := s.client.do(req) if err != nil { return nil, resp, fmt.Errorf("%w", err) } @@ -364,7 +364,7 @@ func (s *AWSService) IAMParameters(ctx context.Context) (*IAMParams, *Response, return nil, nil, fmt.Errorf("%w", err) } - resp, err := s.client.do(ctx, req) + resp, err := s.client.do(req) if err != nil { return nil, resp, fmt.Errorf("%w", err) } @@ -403,7 +403,7 @@ func (s *AWSService) IAMPolicy(ctx context.Context) (*IAMPolicy, *Response, erro return nil, nil, fmt.Errorf("%w", err) } - resp, err := s.client.do(ctx, req) + resp, err := s.client.do(req) if err != nil { return nil, resp, fmt.Errorf("%w", err) } diff --git a/azure.go b/azure.go index 66d47ba..bea843a 100644 --- a/azure.go +++ b/azure.go @@ -85,7 +85,7 @@ func (s *AzureService) List(ctx context.Context) ([]*AzureAccount, *Response, er return nil, nil, fmt.Errorf("%w", err) } - resp, err := s.client.do(ctx, req) + resp, err := s.client.do(req) if err != nil { return nil, resp, fmt.Errorf("%w", err) } @@ -157,7 +157,7 @@ func (s *AzureService) Create(ctx context.Context, account *AzureAccount) (*Azur return nil, nil, fmt.Errorf("%w", err) } - resp, err := s.client.do(ctx, req) + resp, err := s.client.do(req) if err != nil { return nil, resp, fmt.Errorf("%w", err) } @@ -230,7 +230,7 @@ func (s *AzureService) Update(ctx context.Context, account *AzureAccount) (*Resp return nil, fmt.Errorf("%w", err) } - resp, err := s.client.do(ctx, req) + resp, err := s.client.do(req) if err != nil { return resp, fmt.Errorf("%w", err) } @@ -269,7 +269,7 @@ func (s *AzureService) Delete(ctx context.Context, id string) (*Response, error) return nil, fmt.Errorf("%w", err) } - resp, err := s.client.do(ctx, req) + resp, err := s.client.do(req) if err != nil { return resp, fmt.Errorf("%w", err) } @@ -339,7 +339,7 @@ func (s *AzureService) Snapshot( return nil, nil, fmt.Errorf("%w", err) } - resp, err := s.client.do(ctx, req) + resp, err := s.client.do(req) if err != nil { return nil, resp, fmt.Errorf("%w", err) } diff --git a/blueprint.go b/blueprint.go index 069704f..2aa60d1 100644 --- a/blueprint.go +++ b/blueprint.go @@ -228,7 +228,7 @@ func (s *BlueprintService) List(ctx context.Context) ([]*Blueprint, *Response, e return nil, nil, fmt.Errorf("%w", err) } - ret, err := s.client.do(ctx, req) + ret, err := s.client.do(req) if err != nil { return nil, nil, fmt.Errorf("%w", err) } @@ -276,7 +276,7 @@ func (s *BlueprintService) Get(ctx context.Context, id string) (*Blueprint, *Res return nil, nil, fmt.Errorf("%w", err) } - resp, err := s.client.do(ctx, req) + resp, err := s.client.do(req) if err != nil { return nil, nil, fmt.Errorf("%w", err) } @@ -323,7 +323,7 @@ func (s *BlueprintService) Create(ctx context.Context, blueprint *Blueprint) (*B return nil, nil, fmt.Errorf("%w", err) } - resp, err := s.client.do(ctx, req) + resp, err := s.client.do(req) if err != nil { return nil, nil, fmt.Errorf("%w", err) } @@ -379,7 +379,7 @@ func (s *BlueprintService) Update(ctx context.Context, blueprint *Blueprint, eta req.Header.Set("If-Match", etag) } - resp, err := s.client.do(ctx, req) + resp, err := s.client.do(req) if err != nil { return nil, fmt.Errorf("%w", err) } @@ -417,7 +417,7 @@ func (s *BlueprintService) Delete(ctx context.Context, id string) (*Response, er return nil, fmt.Errorf("%w", err) } - resp, err := s.client.do(ctx, req) + resp, err := s.client.do(req) if err != nil { return nil, fmt.Errorf("%w", err) } @@ -479,7 +479,7 @@ func (s *BlueprintService) ExportImage( return nil, nil, fmt.Errorf("%w", err) } - resp, err := s.client.do(ctx, req) + resp, err := s.client.do(req) if err != nil { return nil, nil, fmt.Errorf("%w", err) } @@ -541,7 +541,7 @@ func (s *BlueprintService) ExportBudget( return nil, nil, fmt.Errorf("%w", err) } - resp, err := s.client.do(ctx, req) + resp, err := s.client.do(req) if err != nil { return nil, nil, fmt.Errorf("%w", err) } diff --git a/client.go b/client.go index 421671e..7f8d952 100644 --- a/client.go +++ b/client.go @@ -191,14 +191,11 @@ type Response struct { } // do performs an HTTP request using the underlying HTTP client. -func (c *Client) do(ctx context.Context, req *http.Request) (*Response, error) { - if err := c.rateLimiter.Wait(ctx); err != nil { +func (c *Client) do(req *http.Request) (*Response, error) { + if err := c.rateLimiter.Wait(req.Context()); err != nil { return nil, fmt.Errorf("%w", err) } - // Use the context from the parameter. - req = req.WithContext(ctx) - resp, err := c.httpClient.Do(req) if err != nil { select { diff --git a/client_internal_test.go b/client_internal_test.go index 96f8e5b..997797e 100644 --- a/client_internal_test.go +++ b/client_internal_test.go @@ -225,7 +225,7 @@ func TestDo(t *testing.T) { t.Fatalf("Request() error = %v", err) } - got, err := client.do(tt.context, req) + got, err := client.do(req) if (err != nil) != tt.wantErr { t.Fatalf("Do() error = %v, wantErr %v", err, tt.wantErr) } diff --git a/user.go b/user.go index 94a3a9b..69a98cc 100644 --- a/user.go +++ b/user.go @@ -57,7 +57,7 @@ func (s *UserService) Me(ctx context.Context) (*User, *Response, error) { return nil, nil, err } - ret, err := s.client.do(ctx, req) + ret, err := s.client.do(req) if err != nil { return nil, nil, err }