From 538f17812cbf87184a26bef9fcbc037c1c4f96f1 Mon Sep 17 00:00:00 2001 From: Vijayan Balasubramanian Date: Mon, 24 Aug 2020 13:58:42 -0700 Subject: [PATCH] Use goimports (#214) goimports fixes imports order and also formats like gofmt. --- .github/workflows/esad-cli-test-and-build-workflow.yml | 10 ++++++---- cli/cmd/cat.go | 1 + cli/cmd/create.go | 1 + cli/cmd/delete.go | 1 + cli/cmd/profile.go | 7 ++++--- cli/cmd/root.go | 5 +++-- cli/cmd/start_stop.go | 1 + cli/go.mod | 2 +- cli/go.sum | 2 ++ cli/internal/client/request.go | 3 ++- cli/internal/controller/ad/ad.go | 3 ++- cli/internal/controller/ad/ad_test.go | 5 +++-- cli/internal/controller/ad/mocks/mock_ad.go | 3 ++- cli/internal/controller/es/es.go | 2 +- cli/internal/controller/es/es_test.go | 5 +++-- cli/internal/controller/es/mocks/mock_es.go | 3 ++- cli/internal/entity/ad/ad_test.go | 3 ++- cli/internal/entity/es/es.go | 2 +- cli/internal/gateway/ad/ad_test.go | 3 ++- cli/internal/gateway/ad/mocks/mock_ad.go | 3 ++- cli/internal/gateway/es/es_test.go | 3 ++- cli/internal/gateway/es/mocks/mock_es.go | 3 ++- cli/internal/gateway/gateway.go | 3 ++- cli/internal/handler/ad/ad_test.go | 3 ++- cli/internal/mapper/ad/ad_test.go | 3 ++- 25 files changed, 52 insertions(+), 28 deletions(-) diff --git a/.github/workflows/esad-cli-test-and-build-workflow.yml b/.github/workflows/esad-cli-test-and-build-workflow.yml index e3fbd8ef..ee96191c 100644 --- a/.github/workflows/esad-cli-test-and-build-workflow.yml +++ b/.github/workflows/esad-cli-test-and-build-workflow.yml @@ -39,8 +39,10 @@ jobs: - name: Check out AD CLI uses: actions/checkout@v2 - - name: gofmt - run: gofmt -s -w . + - name: Format + run: | + go get golang.org/x/tools/cmd/goimports + goimports -w . - name: Check for modified files id: git-check run: | @@ -48,9 +50,9 @@ jobs: - name: Display unformated changes if: steps.git-check.outputs.modified == 'true' run: | - echo "Failed to format using go-fmt". + echo "Failed to format using goimports". git diff - + exit 1 - uses: actions/checkout@v2 - name: golangci-lint uses: golangci/golangci-lint-action@v1 diff --git a/cli/cmd/cat.go b/cli/cmd/cat.go index afb0c8cd..0be52c9b 100644 --- a/cli/cmd/cat.go +++ b/cli/cmd/cat.go @@ -17,6 +17,7 @@ import ( entity "esad/internal/entity/ad" "esad/internal/handler/ad" "fmt" + "github.com/spf13/cobra" ) diff --git a/cli/cmd/create.go b/cli/cmd/create.go index 1123fee1..5a3f31e8 100644 --- a/cli/cmd/create.go +++ b/cli/cmd/create.go @@ -15,6 +15,7 @@ package cmd import ( handler "esad/internal/handler/ad" "fmt" + "github.com/spf13/cobra" ) diff --git a/cli/cmd/delete.go b/cli/cmd/delete.go index c3667336..c98f82c0 100644 --- a/cli/cmd/delete.go +++ b/cli/cmd/delete.go @@ -15,6 +15,7 @@ package cmd import ( handler "esad/internal/handler/ad" "fmt" + "github.com/spf13/cobra" ) diff --git a/cli/cmd/profile.go b/cli/cmd/profile.go index 0a764c1d..6b91b3b1 100644 --- a/cli/cmd/profile.go +++ b/cli/cmd/profile.go @@ -17,13 +17,14 @@ import ( "esad/internal/client" entity "esad/internal/entity/ad" "fmt" + "os" + "strings" + "text/tabwriter" + "github.com/mitchellh/mapstructure" "github.com/spf13/cobra" "github.com/spf13/viper" "golang.org/x/crypto/ssh/terminal" - "os" - "strings" - "text/tabwriter" ) const ( diff --git a/cli/cmd/root.go b/cli/cmd/root.go index 348d76a4..9e152be7 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -21,11 +21,12 @@ import ( handler "esad/internal/handler/ad" "esad/pkg" "fmt" + "os" + "path/filepath" + "github.com/mitchellh/go-homedir" "github.com/spf13/cobra" "github.com/spf13/viper" - "os" - "path/filepath" ) const ( diff --git a/cli/cmd/start_stop.go b/cli/cmd/start_stop.go index d5d0c08e..82f7f729 100644 --- a/cli/cmd/start_stop.go +++ b/cli/cmd/start_stop.go @@ -16,6 +16,7 @@ import ( "esad/internal/client" "esad/internal/handler/ad" "fmt" + "github.com/spf13/cobra" ) diff --git a/cli/go.mod b/cli/go.mod index 06476d59..9668b505 100644 --- a/cli/go.mod +++ b/cli/go.mod @@ -22,6 +22,6 @@ require ( golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect golang.org/x/text v0.3.3 // indirect - golang.org/x/tools v0.0.0-20200717024301-6ddee64345a6 // indirect + golang.org/x/tools v0.0.0-20200820180210-c8f393745106 // indirect gopkg.in/ini.v1 v1.57.0 // indirect ) diff --git a/cli/go.sum b/cli/go.sum index d9f95d26..1bd80824 100644 --- a/cli/go.sum +++ b/cli/go.sum @@ -356,6 +356,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200717024301-6ddee64345a6 h1:nULzSsKgihxFGLnQFv2T7lE5vIhOtg8ZPpJHapEt7o0= golang.org/x/tools v0.0.0-20200717024301-6ddee64345a6/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200820180210-c8f393745106 h1:42Zs/g7pjhSIE/wiAuKcp8zp20zv7W2diNU6arpshOA= +golang.org/x/tools v0.0.0-20200820180210-c8f393745106/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= diff --git a/cli/internal/client/request.go b/cli/internal/client/request.go index 7bfd9962..813634f6 100644 --- a/cli/internal/client/request.go +++ b/cli/internal/client/request.go @@ -14,8 +14,9 @@ package client import ( "crypto/tls" - "github.com/hashicorp/go-retryablehttp" "net/http" + + "github.com/hashicorp/go-retryablehttp" ) //Client is an Abstraction for actual client diff --git a/cli/internal/controller/ad/ad.go b/cli/internal/controller/ad/ad.go index 6079d201..827d0cd7 100644 --- a/cli/internal/controller/ad/ad.go +++ b/cli/internal/controller/ad/ad.go @@ -22,10 +22,11 @@ import ( cmapper "esad/internal/mapper" mapper "esad/internal/mapper/ad" "fmt" - "github.com/cheggaaa/pb/v3" "io" "os" "strings" + + "github.com/cheggaaa/pb/v3" ) //go:generate mockgen -destination=mocks/mock_ad.go -package=mocks . Controller diff --git a/cli/internal/controller/ad/ad_test.go b/cli/internal/controller/ad/ad_test.go index 1e78a200..26d58cf1 100644 --- a/cli/internal/controller/ad/ad_test.go +++ b/cli/internal/controller/ad/ad_test.go @@ -22,12 +22,13 @@ import ( adgateway "esad/internal/gateway/ad/mocks" mapper2 "esad/internal/mapper" "fmt" - "github.com/golang/mock/gomock" - "github.com/stretchr/testify/assert" "io/ioutil" "os" "path/filepath" "testing" + + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" ) const mockDetectorID = "m4ccEnIBTXsGi3mvMt9p" diff --git a/cli/internal/controller/ad/mocks/mock_ad.go b/cli/internal/controller/ad/mocks/mock_ad.go index 21afcfa9..19c3fb28 100644 --- a/cli/internal/controller/ad/mocks/mock_ad.go +++ b/cli/internal/controller/ad/mocks/mock_ad.go @@ -7,8 +7,9 @@ package mocks import ( context "context" ad "esad/internal/entity/ad" - gomock "github.com/golang/mock/gomock" reflect "reflect" + + gomock "github.com/golang/mock/gomock" ) // MockController is a mock of Controller interface diff --git a/cli/internal/controller/es/es.go b/cli/internal/controller/es/es.go index c21afc3e..5773d615 100644 --- a/cli/internal/controller/es/es.go +++ b/cli/internal/controller/es/es.go @@ -15,7 +15,7 @@ package es import ( "context" "encoding/json" - "esad/internal/entity/es" + elasticsearch "esad/internal/entity/es" "esad/internal/gateway/es" "fmt" ) diff --git a/cli/internal/controller/es/es_test.go b/cli/internal/controller/es/es_test.go index 14855c42..c8f42157 100644 --- a/cli/internal/controller/es/es_test.go +++ b/cli/internal/controller/es/es_test.go @@ -16,11 +16,12 @@ import ( "context" "errors" gateway "esad/internal/gateway/es/mocks" - "github.com/golang/mock/gomock" - "github.com/stretchr/testify/assert" "io/ioutil" "path/filepath" "testing" + + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" ) func helperLoadBytes(t *testing.T, name string) []byte { diff --git a/cli/internal/controller/es/mocks/mock_es.go b/cli/internal/controller/es/mocks/mock_es.go index 262e265d..7b6af40d 100644 --- a/cli/internal/controller/es/mocks/mock_es.go +++ b/cli/internal/controller/es/mocks/mock_es.go @@ -6,8 +6,9 @@ package mocks import ( context "context" - gomock "github.com/golang/mock/gomock" reflect "reflect" + + gomock "github.com/golang/mock/gomock" ) // MockController is a mock of Controller interface diff --git a/cli/internal/entity/ad/ad_test.go b/cli/internal/entity/ad/ad_test.go index 23e56a5e..8890b1e4 100644 --- a/cli/internal/entity/ad/ad_test.go +++ b/cli/internal/entity/ad/ad_test.go @@ -15,9 +15,10 @@ package ad import ( "encoding/json" "esad/internal/mapper" - "github.com/stretchr/testify/assert" "strings" "testing" + + "github.com/stretchr/testify/assert" ) func getRawFilter() []byte { diff --git a/cli/internal/entity/es/es.go b/cli/internal/entity/es/es.go index 921ccdd3..604bab62 100644 --- a/cli/internal/entity/es/es.go +++ b/cli/internal/entity/es/es.go @@ -10,7 +10,7 @@ * permissions and limitations under the License. */ -package elasticsearch +package es //Terms contains fields type Terms struct { diff --git a/cli/internal/gateway/ad/ad_test.go b/cli/internal/gateway/ad/ad_test.go index 4551198b..9e2ed55b 100644 --- a/cli/internal/gateway/ad/ad_test.go +++ b/cli/internal/gateway/ad/ad_test.go @@ -19,11 +19,12 @@ import ( "esad/internal/client" "esad/internal/client/mocks" "esad/internal/entity/ad" - "github.com/stretchr/testify/assert" "io/ioutil" "net/http" "path/filepath" "testing" + + "github.com/stretchr/testify/assert" ) func helperLoadBytes(t *testing.T, name string) []byte { diff --git a/cli/internal/gateway/ad/mocks/mock_ad.go b/cli/internal/gateway/ad/mocks/mock_ad.go index 7c5f7012..326d7f92 100644 --- a/cli/internal/gateway/ad/mocks/mock_ad.go +++ b/cli/internal/gateway/ad/mocks/mock_ad.go @@ -6,8 +6,9 @@ package mocks import ( context "context" - gomock "github.com/golang/mock/gomock" reflect "reflect" + + gomock "github.com/golang/mock/gomock" ) // MockGateway is a mock of Gateway interface diff --git a/cli/internal/gateway/es/es_test.go b/cli/internal/gateway/es/es_test.go index 4164839e..743e84e6 100644 --- a/cli/internal/gateway/es/es_test.go +++ b/cli/internal/gateway/es/es_test.go @@ -19,11 +19,12 @@ import ( "esad/internal/client" "esad/internal/client/mocks" elasticsearch "esad/internal/entity/es" - "github.com/stretchr/testify/assert" "io/ioutil" "net/http" "path/filepath" "testing" + + "github.com/stretchr/testify/assert" ) func helperLoadBytes(t *testing.T, name string) []byte { diff --git a/cli/internal/gateway/es/mocks/mock_es.go b/cli/internal/gateway/es/mocks/mock_es.go index 7160f51d..7c39d0c4 100644 --- a/cli/internal/gateway/es/mocks/mock_es.go +++ b/cli/internal/gateway/es/mocks/mock_es.go @@ -6,8 +6,9 @@ package mocks import ( context "context" - gomock "github.com/golang/mock/gomock" reflect "reflect" + + gomock "github.com/golang/mock/gomock" ) // MockGateway is a mock of Gateway interface diff --git a/cli/internal/gateway/gateway.go b/cli/internal/gateway/gateway.go index aa36ffcf..037dfbd7 100644 --- a/cli/internal/gateway/gateway.go +++ b/cli/internal/gateway/gateway.go @@ -18,9 +18,10 @@ import ( "encoding/json" "esad/internal/client" "fmt" - "github.com/hashicorp/go-retryablehttp" "io/ioutil" "net/url" + + "github.com/hashicorp/go-retryablehttp" ) //HTTPGateway type for gateway client diff --git a/cli/internal/handler/ad/ad_test.go b/cli/internal/handler/ad/ad_test.go index 55cff918..23dc89c1 100644 --- a/cli/internal/handler/ad/ad_test.go +++ b/cli/internal/handler/ad/ad_test.go @@ -19,9 +19,10 @@ import ( "esad/internal/controller/ad/mocks" "esad/internal/entity/ad" "esad/internal/mapper" + "testing" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" - "testing" ) func getRawFilter() []byte { diff --git a/cli/internal/mapper/ad/ad_test.go b/cli/internal/mapper/ad/ad_test.go index 7beeb4c5..24bb8f2c 100644 --- a/cli/internal/mapper/ad/ad_test.go +++ b/cli/internal/mapper/ad/ad_test.go @@ -15,10 +15,11 @@ package ad import ( "esad/internal/entity/ad" "esad/internal/mapper" - "github.com/stretchr/testify/assert" "io/ioutil" "path/filepath" "testing" + + "github.com/stretchr/testify/assert" ) func helperLoadBytes(t *testing.T, name string) []byte {