From ecb37f1e6b553273003fd7e169bafb75ca20029f Mon Sep 17 00:00:00 2001 From: Wojciech Trocki Date: Thu, 28 Mar 2024 14:55:34 +0100 Subject: [PATCH] Revert "CLOUDP-237245: Add example for retrying requests (#294)" This reverts commit 5ded14ad4c6784747d7b9a07ece4953469abeb62. --- .github/dependabot.yml | 6 ---- .github/workflows/pr.yml | 2 +- .golangci.yml | 6 +++- .tool-versions | 2 +- Makefile | 2 +- examples/README.md | 13 ++------ examples/go.mod | 20 ----------- examples/go.sum | 21 ------------ examples/retry/retry.go | 71 ---------------------------------------- go.mod | 4 +-- go.sum | 4 +-- 11 files changed, 14 insertions(+), 137 deletions(-) delete mode 100644 examples/go.mod delete mode 100644 examples/go.sum delete mode 100644 examples/retry/retry.go diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 72c34673..3ab4516b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,12 +5,6 @@ updates: schedule: interval: weekly day: monday - - package-ecosystem: gomod - directory: "/examples" - schedule: - interval: monthly - ignore: - - dependency-name: "*" - package-ecosystem: github-actions directory: "/" schedule: diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 120b009f..3b91418d 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -20,7 +20,7 @@ jobs: - name: lint uses: golangci/golangci-lint-action@v4.0.0 with: - version: v1.57.1 + version: v1.52.2 args: --timeout=10m tests-on-unix: diff --git a/.golangci.yml b/.golangci.yml index 103ea640..f39d8fc5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -20,6 +20,10 @@ linters-settings: - typeAssertChain gocyclo: min-complexity: 15 + govet: + check-shadowing: true + maligned: + suggest-new: true revive: # see https://github.com/mgechev/revive#available-rules for details. ignore-generated-header: true @@ -69,7 +73,7 @@ linters: disable-all: true enable: - bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false] - #- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: false, auto-fix: false] + - depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: false, auto-fix: false] - dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false] - errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false] - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. [fast: false, auto-fix: false] diff --git a/.tool-versions b/.tool-versions index 9f2448a5..b1a2aa34 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,3 +1,3 @@ -golang 1.22.1 +golang 1.20 nodejs 18.18.2 diff --git a/Makefile b/Makefile index 1ce67da0..767e97c9 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ SOURCE_FILES?=./... -GOLANGCI_VERSION=v1.57.1 +GOLANGCI_VERSION=v1.52.2 COVERAGE=coverage.out export GO111MODULE := on diff --git a/examples/README.md b/examples/README.md index fffc22eb..995ee2b3 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,4 +1,4 @@ -# Go SDK examples +## Go SDK examples ## Running Examples @@ -11,6 +11,7 @@ export MONGODB_ATLAS_PRIVATE_KEY=some-secret-key-for-gosdkapi go run ./aws_cluster/aws.go ``` + ## Running Examples with Mocked Backend SDK provides mocks using Testify and Mockery. @@ -19,13 +20,3 @@ One of the SDK examples covers usage of the mockery within tests. ```bash go test ./mock/cluster_test.go ``` - -## Examples Reference - -### Retry Example - -Example provides automatic retries for all HTTP 500, 429 HTTP status errors. - -```bash -go run ./retry/retry.go -``` diff --git a/examples/go.mod b/examples/go.mod deleted file mode 100644 index 72f67d98..00000000 --- a/examples/go.mod +++ /dev/null @@ -1,20 +0,0 @@ -module go.mongodb.org/atlas-sdk/v20231115008/examples - -go 1.22.1 - -replace go.mongodb.org/atlas-sdk/v20231115008 => ../ - -require ( - github.com/hashicorp/go-retryablehttp v0.7.5 - github.com/mongodb-forks/digest v1.1.0 - go.mongodb.org/atlas-sdk/v20231115008 v20231115008.1.0 -) - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/hashicorp/go-cleanhttp v0.5.2 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/stretchr/objx v0.5.2 // indirect - github.com/stretchr/testify v1.9.0 - gopkg.in/yaml.v3 v3.0.1 // indirect -) diff --git a/examples/go.sum b/examples/go.sum deleted file mode 100644 index 122a182e..00000000 --- a/examples/go.sum +++ /dev/null @@ -1,21 +0,0 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= -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/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= -github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT9yvm0e+Nd5M= -github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8= -github.com/mongodb-forks/digest v1.1.0 h1:7eUdsR1BtqLv0mdNm4OXs6ddWvR4X2/OsLwdKksrOoc= -github.com/mongodb-forks/digest v1.1.0/go.mod h1:rb+EX8zotClD5Dj4NdgxnJXG9nwrlx3NWKJ8xttz1Dg= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -go.mongodb.org/atlas-sdk/v20231115008 v20231115008.1.0 h1:WKPkreeCuIh2KKxfEP6KWIFNdNYaXnfSg79v2zAaSjw= -go.mongodb.org/atlas-sdk/v20231115008 v20231115008.1.0/go.mod h1:BHskDmYvvANe+s/HMkRhvK3GudGEZuzjYSbp1fBssdc= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/examples/retry/retry.go b/examples/retry/retry.go deleted file mode 100644 index 31ea0025..00000000 --- a/examples/retry/retry.go +++ /dev/null @@ -1,71 +0,0 @@ -package main - -import ( - "fmt" - "log" - "net/http" - "os" - - "context" - - "go.mongodb.org/atlas-sdk/v20231115008/admin" - - retryablehttp "github.com/hashicorp/go-retryablehttp" - "github.com/mongodb-forks/digest" -) - -/* -* MongoDB Atlas Go SDK Retryable Request Example -* -* Example using custom http client that handles rate limiting and 500 Http errors by retrying requests automatically. -* Example uses https://pkg.go.dev/github.com/hashicorp/go-retryablehttp. -* Please refer to the package documentation for more information. - */ -func main() { - ctx := context.Background() - // Values provided as part of env variables - // See: https://www.mongodb.com/docs/atlas/app-services/authentication/api-key/ - apiKey := os.Getenv("MONGODB_ATLAS_PUBLIC_KEY") - apiSecret := os.Getenv("MONGODB_ATLAS_PRIVATE_KEY") - url := os.Getenv("MONGODB_ATLAS_URL") - - // Using custom client - // This example relies on https://pkg.go.dev/github.com/hashicorp/go-retryablehttp - // 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 is received, then a retry is invoked. - retryClient := retryablehttp.NewClient() - retryClient.RetryMax = 3 - - retryableClient, err := newRetryableClient(retryClient, apiKey, apiSecret) - if err != nil { - log.Fatal("Cannot instantiate client") - } - sdk, err := admin.NewClient( - admin.UseHTTPClient(retryableClient), - admin.UseBaseURL(url), - admin.UseDebug(false)) - if err != nil { - log.Fatal(err) - } - - request := sdk.ProjectsApi.ListProjectsWithParams(ctx, - &admin.ListProjectsApiParams{ - ItemsPerPage: admin.PtrInt(1), - IncludeCount: admin.PtrBool(true), - PageNum: admin.PtrInt(1), - }) - projects, _, err := request.Execute() - if err != nil { - log.Fatal(err) - } - - fmt.Println("Total Projects", projects.GetTotalCount()) - -} - -func newRetryableClient(retryClient *retryablehttp.Client, apiKey string, apiSecret string) (*http.Client, error) { - var transport http.RoundTripper = &retryablehttp.RoundTripper{Client: retryClient} - digestRetryAbleTransport := digest.NewTransportWithHTTPRoundTripper(apiKey, apiSecret, transport) - return digestRetryAbleTransport.Client() -} diff --git a/go.mod b/go.mod index e677f781..59c00c8e 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,10 @@ module go.mongodb.org/atlas-sdk/v20231115008 -go 1.22.1 +go 1.20 require ( github.com/go-test/deep v1.1.0 - github.com/mongodb-forks/digest v1.1.0 + github.com/mongodb-forks/digest v1.0.5 ) require ( diff --git a/go.sum b/go.sum index c055d133..c02d945a 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg= github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= -github.com/mongodb-forks/digest v1.1.0 h1:7eUdsR1BtqLv0mdNm4OXs6ddWvR4X2/OsLwdKksrOoc= -github.com/mongodb-forks/digest v1.1.0/go.mod h1:rb+EX8zotClD5Dj4NdgxnJXG9nwrlx3NWKJ8xttz1Dg= +github.com/mongodb-forks/digest v1.0.5 h1:EJu3wtLZcA0HCvsZpX5yuD193/sW9tHiNvrEM5apXMk= +github.com/mongodb-forks/digest v1.0.5/go.mod h1:rb+EX8zotClD5Dj4NdgxnJXG9nwrlx3NWKJ8xttz1Dg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=