From cd6a321af5bc90f465bd72edfe710e0d8268fff3 Mon Sep 17 00:00:00 2001 From: ccoVeille <3875889+ccoVeille@users.noreply.github.com> Date: Sun, 7 Jul 2024 18:14:52 +0200 Subject: [PATCH] ci: enable recent gci linter options and fix reported errors (#798) --- .golangci.yml | 4 +++- examples/grpc-server/grpc/hello.pb.go | 5 +++-- examples/grpc-server/grpc/hello_grpc.pb.go | 1 + examples/using-file-bind/main_test.go | 3 ++- examples/using-migrations/main.go | 1 - .../migrations/1708322067_create_employee_table_test.go | 1 + .../migrations/1708322089_redis_add_employee_name.go | 1 + .../migrations/1708322089_redis_add_employee_name_test.go | 1 + examples/using-publisher/main.go | 1 + pkg/gofr/container/container.go | 1 + pkg/gofr/container/mock_datasources.go | 1 + pkg/gofr/datasource/clickhouse/clickhouse_test.go | 3 +-- pkg/gofr/datasource/mongo/mongo_test.go | 1 - pkg/gofr/datasource/pubsub/google/health.go | 3 ++- pkg/gofr/datasource/pubsub/mqtt/mock_interfaces.go | 1 + pkg/gofr/datasource/redis/hook.go | 4 ++-- pkg/gofr/datasource/redis/redis_test.go | 1 - pkg/gofr/exporter.go | 1 + pkg/gofr/grpc.go | 2 +- pkg/gofr/http/middleware/basic_auth_test.go | 1 + pkg/gofr/http/middleware/metrics_test.go | 7 +++---- pkg/gofr/http/middleware/web_socket.go | 4 ++-- pkg/gofr/http/middleware/web_socket_test.go | 1 + pkg/gofr/logging/remotelogger/dynamicLevelLogger_test.go | 1 + pkg/gofr/migration/interface.go | 1 + pkg/gofr/migration/mock_interface.go | 1 + pkg/gofr/service/circuit_breaker_test.go | 1 + pkg/gofr/service/retry_test.go | 4 ++-- pkg/gofr/websocket/websocket_test.go | 3 +-- 29 files changed, 37 insertions(+), 23 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index e6f9ed0e1..8dcfe1ab0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -9,7 +9,9 @@ linters-settings: statements: 50 gci: sections: - - prefix(gofr.dev) + - standard + - default + - localmodule goconst: min-len: 2 min-occurrences: 2 diff --git a/examples/grpc-server/grpc/hello.pb.go b/examples/grpc-server/grpc/hello.pb.go index bf0743cee..a9c00225f 100644 --- a/examples/grpc-server/grpc/hello.pb.go +++ b/examples/grpc-server/grpc/hello.pb.go @@ -7,10 +7,11 @@ package grpc import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" + + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" ) const ( diff --git a/examples/grpc-server/grpc/hello_grpc.pb.go b/examples/grpc-server/grpc/hello_grpc.pb.go index 9b144e915..83c78fa20 100644 --- a/examples/grpc-server/grpc/hello_grpc.pb.go +++ b/examples/grpc-server/grpc/hello_grpc.pb.go @@ -8,6 +8,7 @@ package grpc import ( context "context" + grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" diff --git a/examples/using-file-bind/main_test.go b/examples/using-file-bind/main_test.go index 6ef70a23c..25413dc1a 100644 --- a/examples/using-file-bind/main_test.go +++ b/examples/using-file-bind/main_test.go @@ -2,13 +2,14 @@ package main import ( "bytes" - "github.com/stretchr/testify/assert" "io" "mime/multipart" "net/http" "os" "testing" "time" + + "github.com/stretchr/testify/assert" ) func TestMain_BindError(t *testing.T) { diff --git a/examples/using-migrations/main.go b/examples/using-migrations/main.go index c8f0161b1..74f7fbabf 100644 --- a/examples/using-migrations/main.go +++ b/examples/using-migrations/main.go @@ -5,7 +5,6 @@ import ( "fmt" "gofr.dev/examples/using-migrations/migrations" - "gofr.dev/pkg/gofr" ) diff --git a/examples/using-migrations/migrations/1708322067_create_employee_table_test.go b/examples/using-migrations/migrations/1708322067_create_employee_table_test.go index 2aae7505f..9a4473c49 100644 --- a/examples/using-migrations/migrations/1708322067_create_employee_table_test.go +++ b/examples/using-migrations/migrations/1708322067_create_employee_table_test.go @@ -6,6 +6,7 @@ import ( "github.com/DATA-DOG/go-sqlmock" "github.com/stretchr/testify/assert" + "gofr.dev/pkg/gofr/migration" ) diff --git a/examples/using-migrations/migrations/1708322089_redis_add_employee_name.go b/examples/using-migrations/migrations/1708322089_redis_add_employee_name.go index dc28e8db4..6d16468a4 100644 --- a/examples/using-migrations/migrations/1708322089_redis_add_employee_name.go +++ b/examples/using-migrations/migrations/1708322089_redis_add_employee_name.go @@ -2,6 +2,7 @@ package migrations import ( "context" + "gofr.dev/pkg/gofr/migration" ) diff --git a/examples/using-migrations/migrations/1708322089_redis_add_employee_name_test.go b/examples/using-migrations/migrations/1708322089_redis_add_employee_name_test.go index 6d1eda832..3390107d6 100644 --- a/examples/using-migrations/migrations/1708322089_redis_add_employee_name_test.go +++ b/examples/using-migrations/migrations/1708322089_redis_add_employee_name_test.go @@ -6,6 +6,7 @@ import ( "github.com/go-redis/redismock/v9" "github.com/stretchr/testify/assert" + "gofr.dev/pkg/gofr/migration" ) diff --git a/examples/using-publisher/main.go b/examples/using-publisher/main.go index ac0c8107f..1fb22cfb9 100644 --- a/examples/using-publisher/main.go +++ b/examples/using-publisher/main.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "gofr.dev/pkg/gofr" ) diff --git a/pkg/gofr/container/container.go b/pkg/gofr/container/container.go index 96e42493e..056ce47cf 100644 --- a/pkg/gofr/container/container.go +++ b/pkg/gofr/container/container.go @@ -6,6 +6,7 @@ import ( "time" _ "github.com/go-sql-driver/mysql" // This is required to be blank import + "gofr.dev/pkg/gofr/config" "gofr.dev/pkg/gofr/datasource" "gofr.dev/pkg/gofr/datasource/file" diff --git a/pkg/gofr/container/mock_datasources.go b/pkg/gofr/container/mock_datasources.go index e7fc2c130..199cb8d64 100644 --- a/pkg/gofr/container/mock_datasources.go +++ b/pkg/gofr/container/mock_datasources.go @@ -17,6 +17,7 @@ import ( redis "github.com/redis/go-redis/v9" gomock "go.uber.org/mock/gomock" + datasource "gofr.dev/pkg/gofr/datasource" sql0 "gofr.dev/pkg/gofr/datasource/sql" ) diff --git a/pkg/gofr/datasource/clickhouse/clickhouse_test.go b/pkg/gofr/datasource/clickhouse/clickhouse_test.go index 48304ee7a..e2f7578f3 100644 --- a/pkg/gofr/datasource/clickhouse/clickhouse_test.go +++ b/pkg/gofr/datasource/clickhouse/clickhouse_test.go @@ -9,9 +9,8 @@ import ( "testing" "time" - "go.uber.org/mock/gomock" - "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" ) func getClickHouseTestConnection(t *testing.T) (*MockConn, *MockMetrics, client) { diff --git a/pkg/gofr/datasource/mongo/mongo_test.go b/pkg/gofr/datasource/mongo/mongo_test.go index 07b20c9a2..f0bcfc91f 100644 --- a/pkg/gofr/datasource/mongo/mongo_test.go +++ b/pkg/gofr/datasource/mongo/mongo_test.go @@ -3,7 +3,6 @@ package mongo import ( "context" "fmt" - "testing" "github.com/stretchr/testify/assert" diff --git a/pkg/gofr/datasource/pubsub/google/health.go b/pkg/gofr/datasource/pubsub/google/health.go index 2f4c59630..a2306da2f 100644 --- a/pkg/gofr/datasource/pubsub/google/health.go +++ b/pkg/gofr/datasource/pubsub/google/health.go @@ -5,8 +5,9 @@ import ( "errors" "time" - "gofr.dev/pkg/gofr/datasource" "google.golang.org/api/iterator" + + "gofr.dev/pkg/gofr/datasource" ) func (g *googleClient) Health() (health datasource.Health) { diff --git a/pkg/gofr/datasource/pubsub/mqtt/mock_interfaces.go b/pkg/gofr/datasource/pubsub/mqtt/mock_interfaces.go index 4d9546e55..7c2e5c8d3 100644 --- a/pkg/gofr/datasource/pubsub/mqtt/mock_interfaces.go +++ b/pkg/gofr/datasource/pubsub/mqtt/mock_interfaces.go @@ -14,6 +14,7 @@ import ( reflect "reflect" gomock "go.uber.org/mock/gomock" + datasource "gofr.dev/pkg/gofr/datasource" ) diff --git a/pkg/gofr/datasource/redis/hook.go b/pkg/gofr/datasource/redis/hook.go index 78b68cc54..e373e62b2 100644 --- a/pkg/gofr/datasource/redis/hook.go +++ b/pkg/gofr/datasource/redis/hook.go @@ -8,9 +8,9 @@ import ( "strings" "time" - "gofr.dev/pkg/gofr/datasource" - "github.com/redis/go-redis/v9" + + "gofr.dev/pkg/gofr/datasource" ) // redisHook is a custom Redis hook for logging queries and their durations. diff --git a/pkg/gofr/datasource/redis/redis_test.go b/pkg/gofr/datasource/redis/redis_test.go index 40d22c937..daa349022 100644 --- a/pkg/gofr/datasource/redis/redis_test.go +++ b/pkg/gofr/datasource/redis/redis_test.go @@ -7,7 +7,6 @@ import ( "github.com/alicebob/miniredis/v2" "github.com/stretchr/testify/assert" - "go.uber.org/mock/gomock" "gofr.dev/pkg/gofr/config" diff --git a/pkg/gofr/exporter.go b/pkg/gofr/exporter.go index f108310fd..73558c3b8 100644 --- a/pkg/gofr/exporter.go +++ b/pkg/gofr/exporter.go @@ -12,6 +12,7 @@ import ( "go.opentelemetry.io/otel/attribute" sdktrace "go.opentelemetry.io/otel/sdk/trace" + "gofr.dev/pkg/gofr/logging" ) diff --git a/pkg/gofr/grpc.go b/pkg/gofr/grpc.go index 939fea12b..be65ef760 100644 --- a/pkg/gofr/grpc.go +++ b/pkg/gofr/grpc.go @@ -6,10 +6,10 @@ import ( grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery" - grpc2 "gofr.dev/pkg/gofr/grpc" "google.golang.org/grpc" "gofr.dev/pkg/gofr/container" + grpc2 "gofr.dev/pkg/gofr/grpc" ) type grpcServer struct { diff --git a/pkg/gofr/http/middleware/basic_auth_test.go b/pkg/gofr/http/middleware/basic_auth_test.go index c471f5d84..a3a10bfb7 100644 --- a/pkg/gofr/http/middleware/basic_auth_test.go +++ b/pkg/gofr/http/middleware/basic_auth_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "gofr.dev/pkg/gofr/container" ) diff --git a/pkg/gofr/http/middleware/metrics_test.go b/pkg/gofr/http/middleware/metrics_test.go index 305705131..abba8e576 100644 --- a/pkg/gofr/http/middleware/metrics_test.go +++ b/pkg/gofr/http/middleware/metrics_test.go @@ -2,13 +2,12 @@ package middleware import ( "context" - - "github.com/gorilla/mux" - "github.com/stretchr/testify/mock" - "net/http" "net/http/httptest" "testing" + + "github.com/gorilla/mux" + "github.com/stretchr/testify/mock" ) type mockMetrics struct { diff --git a/pkg/gofr/http/middleware/web_socket.go b/pkg/gofr/http/middleware/web_socket.go index 34637717f..346e99df1 100644 --- a/pkg/gofr/http/middleware/web_socket.go +++ b/pkg/gofr/http/middleware/web_socket.go @@ -4,10 +4,10 @@ import ( "context" "net/http" + gorillaWebsocket "github.com/gorilla/websocket" + "gofr.dev/pkg/gofr/container" "gofr.dev/pkg/gofr/websocket" - - gorillaWebsocket "github.com/gorilla/websocket" ) // WSHandlerUpgrade middleware upgrades the incoming http request to a websocket connection using websocket upgrader. diff --git a/pkg/gofr/http/middleware/web_socket_test.go b/pkg/gofr/http/middleware/web_socket_test.go index 5f812c183..0e65a7909 100644 --- a/pkg/gofr/http/middleware/web_socket_test.go +++ b/pkg/gofr/http/middleware/web_socket_test.go @@ -9,6 +9,7 @@ import ( "github.com/gorilla/websocket" "github.com/stretchr/testify/assert" "go.uber.org/mock/gomock" + "gofr.dev/pkg/gofr/container" gofrWebSocket "gofr.dev/pkg/gofr/websocket" ) diff --git a/pkg/gofr/logging/remotelogger/dynamicLevelLogger_test.go b/pkg/gofr/logging/remotelogger/dynamicLevelLogger_test.go index 71bda6f4d..c273d0edb 100644 --- a/pkg/gofr/logging/remotelogger/dynamicLevelLogger_test.go +++ b/pkg/gofr/logging/remotelogger/dynamicLevelLogger_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "gofr.dev/pkg/gofr/logging" "gofr.dev/pkg/gofr/service" "gofr.dev/pkg/gofr/testutil" diff --git a/pkg/gofr/migration/interface.go b/pkg/gofr/migration/interface.go index ce7934c31..2c8fe12c2 100644 --- a/pkg/gofr/migration/interface.go +++ b/pkg/gofr/migration/interface.go @@ -6,6 +6,7 @@ import ( "time" goRedis "github.com/redis/go-redis/v9" + "gofr.dev/pkg/gofr/container" ) diff --git a/pkg/gofr/migration/mock_interface.go b/pkg/gofr/migration/mock_interface.go index 9a7db0462..79f982637 100644 --- a/pkg/gofr/migration/mock_interface.go +++ b/pkg/gofr/migration/mock_interface.go @@ -17,6 +17,7 @@ import ( redis "github.com/redis/go-redis/v9" gomock "go.uber.org/mock/gomock" + container "gofr.dev/pkg/gofr/container" ) diff --git a/pkg/gofr/service/circuit_breaker_test.go b/pkg/gofr/service/circuit_breaker_test.go index 0d6ad8f34..681b72faf 100644 --- a/pkg/gofr/service/circuit_breaker_test.go +++ b/pkg/gofr/service/circuit_breaker_test.go @@ -11,6 +11,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "go.opentelemetry.io/otel" + "gofr.dev/pkg/gofr/logging" "gofr.dev/pkg/gofr/testutil" ) diff --git a/pkg/gofr/service/retry_test.go b/pkg/gofr/service/retry_test.go index 2511b1b78..9219f0eab 100644 --- a/pkg/gofr/service/retry_test.go +++ b/pkg/gofr/service/retry_test.go @@ -6,9 +6,9 @@ import ( "net/http/httptest" "testing" - "gofr.dev/pkg/gofr/logging" - "github.com/stretchr/testify/assert" + + "gofr.dev/pkg/gofr/logging" ) type mockHTTP struct{} diff --git a/pkg/gofr/websocket/websocket_test.go b/pkg/gofr/websocket/websocket_test.go index 1dc73cb85..88437f01a 100644 --- a/pkg/gofr/websocket/websocket_test.go +++ b/pkg/gofr/websocket/websocket_test.go @@ -7,10 +7,9 @@ import ( "testing" "time" - "go.uber.org/mock/gomock" - "github.com/gorilla/websocket" "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" ) func TestConnection_Bind_Success(t *testing.T) {