From 72b53888ca89a33512b2c45ef994d4625faacd0a Mon Sep 17 00:00:00 2001 From: yeebing Date: Tue, 19 Sep 2023 12:56:14 +0800 Subject: [PATCH] style: fix code lint --- components/cryption/aliyun/kms.go | 3 ++- components/cryption/aws/kms.go | 3 ++- pkg/common/file_test.go | 3 ++- pkg/runtime/pluggable.go | 12 ++++++------ pkg/runtime/pluggable_test.go | 16 +++++++++------- spec/proto/extension/v1/cryption/cryption.pb.go | 5 +++-- .../extension/v1/cryption/cryption_grpc.pb.go | 1 + 7 files changed, 25 insertions(+), 18 deletions(-) diff --git a/components/cryption/aliyun/kms.go b/components/cryption/aliyun/kms.go index d4b6bcd50c..18f76da25e 100644 --- a/components/cryption/aliyun/kms.go +++ b/components/cryption/aliyun/kms.go @@ -22,8 +22,9 @@ import ( openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client" kms20160120 "github.com/alibabacloud-go/kms-20160120/v3/client" "github.com/alibabacloud-go/tea/tea" - "mosn.io/layotto/components/cryption" "mosn.io/pkg/log" + + "mosn.io/layotto/components/cryption" ) type cy struct { diff --git a/components/cryption/aws/kms.go b/components/cryption/aws/kms.go index 03aa756d7c..fa2a90c599 100644 --- a/components/cryption/aws/kms.go +++ b/components/cryption/aws/kms.go @@ -23,8 +23,9 @@ import ( "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/kms" - "mosn.io/layotto/components/cryption" "mosn.io/pkg/log" + + "mosn.io/layotto/components/cryption" ) type cy struct { diff --git a/pkg/common/file_test.go b/pkg/common/file_test.go index 0cc4d1c59d..fe8972f34c 100644 --- a/pkg/common/file_test.go +++ b/pkg/common/file_test.go @@ -17,8 +17,9 @@ package common import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestGetFileSize(t *testing.T) { diff --git a/pkg/runtime/pluggable.go b/pkg/runtime/pluggable.go index 950cf2cc82..f137b3930b 100644 --- a/pkg/runtime/pluggable.go +++ b/pkg/runtime/pluggable.go @@ -90,18 +90,18 @@ func (m *MosnRuntime) RegisterPluggableComponent() error { } // 1. discover pluggable component - services, err := m.Discover() + services, err := m.discover() if err != nil { return err } // 2. callback to register factory into MosnRuntime - m.Callback(services) + m.callback(services) return nil } -// Discover use grpc reflect to get services information. -func (m *MosnRuntime) Discover() ([]pluggableComponentService, error) { +// discover use grpc reflect to get services information. +func (m *MosnRuntime) discover() ([]pluggableComponentService, error) { ctx := context.TODO() services, err := serviceDiscovery(func(socket string) (client reflectServiceClient, closer func(), err error) { conn, err := grpcdial.SocketDial( @@ -189,8 +189,8 @@ func serviceDiscovery(reflectClientFactory func(socket string) (client reflectSe return services, nil } -// Callback use callback function to register pluggable component factories into MosnRuntime -func (m *MosnRuntime) Callback(services []pluggableComponentService) { +// callback use callback function to register pluggable component factories into MosnRuntime +func (m *MosnRuntime) callback(services []pluggableComponentService) { for _, service := range services { callback, ok := onServiceDiscovered[service.protoRef] if !ok { diff --git a/pkg/runtime/pluggable_test.go b/pkg/runtime/pluggable_test.go index 2ad910fa3a..696fb99c81 100644 --- a/pkg/runtime/pluggable_test.go +++ b/pkg/runtime/pluggable_test.go @@ -15,14 +15,16 @@ package runtime import ( "errors" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - grpcdial "mosn.io/layotto/pkg/grpc" "net" "os" "runtime" "sync" "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + grpcdial "mosn.io/layotto/pkg/grpc" ) type fakeReflectService struct { @@ -83,7 +85,7 @@ func TestMosnRuntime_Callback(t *testing.T) { called++ assert.Equal(t, name, fakeComponentName) }) - m.Callback([]pluggableComponentService{{protoRef: fakeServiceName, componentName: fakeComponentName}}) + m.callback([]pluggableComponentService{{protoRef: fakeServiceName, componentName: fakeComponentName}}) assert.Equal(t, 1, called) }) } @@ -193,11 +195,11 @@ func Test_serviceDiscovery(t *testing.T) { func TestConnectionCloser(t *testing.T) { t.Run("connection closer should call grpc close and client reset", func(t *testing.T) { - const close, reset = "close", "reset" + const closed, reset = "closed", "reset" callOrder := []string{} fakeCloser := &fakeGrpcCloser{ onCloseCalled: func() { - callOrder = append(callOrder, close) + callOrder = append(callOrder, closed) }, } fakeService := &fakeReflectService{ @@ -208,6 +210,6 @@ func TestConnectionCloser(t *testing.T) { closer := reflectServiceConnectionCloser(fakeCloser, fakeService) closer() assert.Len(t, callOrder, 2) - assert.Equal(t, callOrder, []string{reset, close}) + assert.Equal(t, callOrder, []string{reset, closed}) }) } diff --git a/spec/proto/extension/v1/cryption/cryption.pb.go b/spec/proto/extension/v1/cryption/cryption.pb.go index 4a50d05f40..9e0877dce8 100644 --- a/spec/proto/extension/v1/cryption/cryption.pb.go +++ b/spec/proto/extension/v1/cryption/cryption.pb.go @@ -7,10 +7,11 @@ package cryption 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/spec/proto/extension/v1/cryption/cryption_grpc.pb.go b/spec/proto/extension/v1/cryption/cryption_grpc.pb.go index 3084ae9851..bf6f4f89cd 100644 --- a/spec/proto/extension/v1/cryption/cryption_grpc.pb.go +++ b/spec/proto/extension/v1/cryption/cryption_grpc.pb.go @@ -8,6 +8,7 @@ package cryption import ( context "context" + grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status"