diff --git a/NOTICE b/NOTICE index d7aa899d1cef0fba67826bebd0d587e9cc17ba5d..1120c200c997fe6befbe3f78d95e9bdb8a05a487 100644 --- a/NOTICE +++ b/NOTICE @@ -1,4 +1,4 @@ -Apache Dubbo Go +Apache Dubbo-go Copyright 2018-2020 The Apache Software Foundation This product includes software developed at diff --git a/cluster/cluster_impl/available_cluster.go b/cluster/cluster_impl/available_cluster.go index b70a97fad2de1b267ac1c6a5f0672ff445fadcc3..ebd5767e4c320f10c8911cf9ac3f2c81deaafb0e 100644 --- a/cluster/cluster_impl/available_cluster.go +++ b/cluster/cluster_impl/available_cluster.go @@ -38,6 +38,7 @@ func NewAvailableCluster() cluster.Cluster { return &availableCluster{} } +// Join returns a baseClusterInvoker instance func (cluser *availableCluster) Join(directory cluster.Directory) protocol.Invoker { return NewAvailableClusterInvoker(directory) } diff --git a/cluster/cluster_impl/broadcast_cluster.go b/cluster/cluster_impl/broadcast_cluster.go index ba454af6a8553f31b72b1d30ef5f44ec7a8278d2..ea3dee921888baa8f997cd02e92ee582f09a37d5 100644 --- a/cluster/cluster_impl/broadcast_cluster.go +++ b/cluster/cluster_impl/broadcast_cluster.go @@ -39,6 +39,7 @@ func NewBroadcastCluster() cluster.Cluster { return &broadcastCluster{} } +// Join returns a baseClusterInvoker instance func (cluster *broadcastCluster) Join(directory cluster.Directory) protocol.Invoker { return newBroadcastClusterInvoker(directory) } diff --git a/cluster/cluster_impl/broadcast_cluster_invoker.go b/cluster/cluster_impl/broadcast_cluster_invoker.go index 3a97d3d9b499c011ac90cb88b6692565388411a7..b117dbb246bec6fed6ced4fb4abcdeb4a4b7cee5 100644 --- a/cluster/cluster_impl/broadcast_cluster_invoker.go +++ b/cluster/cluster_impl/broadcast_cluster_invoker.go @@ -36,6 +36,7 @@ func newBroadcastClusterInvoker(directory cluster.Directory) protocol.Invoker { } } +// nolint func (invoker *broadcastClusterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result { invokers := invoker.directory.List(invocation) err := invoker.checkInvokers(invokers, invocation) diff --git a/cluster/cluster_impl/failback_cluster.go b/cluster/cluster_impl/failback_cluster.go index 432e33122c2ee599bc848ca9ab1842084da5ef68..278ac5432e7db5d8379e4aba81065ff2ab704ff5 100644 --- a/cluster/cluster_impl/failback_cluster.go +++ b/cluster/cluster_impl/failback_cluster.go @@ -39,6 +39,7 @@ func NewFailbackCluster() cluster.Cluster { return &failbackCluster{} } +// Join returns a baseClusterInvoker instance func (cluster *failbackCluster) Join(directory cluster.Directory) protocol.Invoker { return newFailbackClusterInvoker(directory) } diff --git a/cluster/cluster_impl/failback_cluster_invoker.go b/cluster/cluster_impl/failback_cluster_invoker.go index af17a93756a6f558c7da063eec9d8052b83cbe69..62f48045ec6edbc19d6603509fa1ae8c2d4ce9ee 100644 --- a/cluster/cluster_impl/failback_cluster_invoker.go +++ b/cluster/cluster_impl/failback_cluster_invoker.go @@ -126,6 +126,7 @@ func (invoker *failbackClusterInvoker) checkRetry(retryTask *retryTimerTask, err } } +// nolint func (invoker *failbackClusterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result { invokers := invoker.directory.List(invocation) if err := invoker.checkInvokers(invokers, invocation); err != nil { diff --git a/cluster/cluster_impl/failfast_cluster.go b/cluster/cluster_impl/failfast_cluster.go index ac9ec6b821c1d0333c73fae56169d5bc8256ec5b..a5ea7a05855e58b9db02f41fcfba83b52d35d8b0 100644 --- a/cluster/cluster_impl/failfast_cluster.go +++ b/cluster/cluster_impl/failfast_cluster.go @@ -39,6 +39,7 @@ func NewFailFastCluster() cluster.Cluster { return &failfastCluster{} } +// Join returns a baseClusterInvoker instance func (cluster *failfastCluster) Join(directory cluster.Directory) protocol.Invoker { return newFailFastClusterInvoker(directory) } diff --git a/cluster/cluster_impl/failfast_cluster_invoker.go b/cluster/cluster_impl/failfast_cluster_invoker.go index 3b4dc9b721720948cf635f57191d1e6bce023a1e..d71ef5f5a1dfed2d29f6ae4f29fb08d34aae9c5d 100644 --- a/cluster/cluster_impl/failfast_cluster_invoker.go +++ b/cluster/cluster_impl/failfast_cluster_invoker.go @@ -35,6 +35,7 @@ func newFailFastClusterInvoker(directory cluster.Directory) protocol.Invoker { } } +// nolint func (invoker *failfastClusterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result { invokers := invoker.directory.List(invocation) err := invoker.checkInvokers(invokers, invocation) diff --git a/cluster/cluster_impl/failover_cluster.go b/cluster/cluster_impl/failover_cluster.go index d30a743e034dafabad87381cdaa356e7603b74d1..254cc097e3e7f0cc70dfcff01212562bc6febe97 100644 --- a/cluster/cluster_impl/failover_cluster.go +++ b/cluster/cluster_impl/failover_cluster.go @@ -40,6 +40,7 @@ func NewFailoverCluster() cluster.Cluster { return &failoverCluster{} } +// Join returns a baseClusterInvoker instance func (cluster *failoverCluster) Join(directory cluster.Directory) protocol.Invoker { return newFailoverClusterInvoker(directory) } diff --git a/cluster/cluster_impl/failover_cluster_invoker.go b/cluster/cluster_impl/failover_cluster_invoker.go index 66adabd1043d6e5d770704774dda22ba9e6faebe..2ce393cc3c84479b95d5df3d7e8ab47c0ca07e74 100644 --- a/cluster/cluster_impl/failover_cluster_invoker.go +++ b/cluster/cluster_impl/failover_cluster_invoker.go @@ -44,6 +44,7 @@ func newFailoverClusterInvoker(directory cluster.Directory) protocol.Invoker { } } +// nolint func (invoker *failoverClusterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result { var ( result protocol.Result diff --git a/cluster/cluster_impl/failover_cluster_test.go b/cluster/cluster_impl/failover_cluster_test.go index e05b79202cd202334db1c19421e3163ee28bac26..d3ac2c8a5ffd7fce647649c53fe343ba93999636 100644 --- a/cluster/cluster_impl/failover_cluster_test.go +++ b/cluster/cluster_impl/failover_cluster_test.go @@ -43,6 +43,7 @@ import ( // mock invoker // /////////////////////////// +// nolint type MockInvoker struct { url common.URL available bool @@ -51,6 +52,7 @@ type MockInvoker struct { successCount int } +// nolint func NewMockInvoker(url common.URL, successCount int) *MockInvoker { return &MockInvoker{ url: url, @@ -60,23 +62,28 @@ func NewMockInvoker(url common.URL, successCount int) *MockInvoker { } } +// nolint func (bi *MockInvoker) GetUrl() common.URL { return bi.url } +// nolint func (bi *MockInvoker) IsAvailable() bool { return bi.available } +// nolint func (bi *MockInvoker) IsDestroyed() bool { return bi.destroyed } +// nolint type rest struct { tried int success bool } +// nolint func (bi *MockInvoker) Invoke(c context.Context, invocation protocol.Invocation) protocol.Result { count++ var ( @@ -93,14 +100,17 @@ func (bi *MockInvoker) Invoke(c context.Context, invocation protocol.Invocation) return result } +// nolint func (bi *MockInvoker) Destroy() { logger.Infof("Destroy invoker: %v", bi.GetUrl().String()) bi.destroyed = true bi.available = false } +// nolint var count int +// nolint func normalInvoke(successCount int, urlParam url.Values, invocations ...*invocation.RPCInvocation) protocol.Result { extension.SetLoadbalance("random", loadbalance.NewRandomLoadBalance) failoverCluster := NewFailoverCluster() @@ -119,6 +129,7 @@ func normalInvoke(successCount int, urlParam url.Values, invocations ...*invocat return clusterInvoker.Invoke(context.Background(), &invocation.RPCInvocation{}) } +// nolint func TestFailoverInvokeSuccess(t *testing.T) { urlParams := url.Values{} result := normalInvoke(3, urlParams) @@ -126,6 +137,7 @@ func TestFailoverInvokeSuccess(t *testing.T) { count = 0 } +// nolint func TestFailoverInvokeFail(t *testing.T) { urlParams := url.Values{} result := normalInvoke(4, urlParams) @@ -133,6 +145,7 @@ func TestFailoverInvokeFail(t *testing.T) { count = 0 } +// nolint func TestFailoverInvoke1(t *testing.T) { urlParams := url.Values{} urlParams.Set(constant.RETRIES_KEY, "3") @@ -141,6 +154,7 @@ func TestFailoverInvoke1(t *testing.T) { count = 0 } +// nolint func TestFailoverInvoke2(t *testing.T) { urlParams := url.Values{} urlParams.Set(constant.RETRIES_KEY, "2") @@ -152,6 +166,7 @@ func TestFailoverInvoke2(t *testing.T) { count = 0 } +// nolint func TestFailoverDestroy(t *testing.T) { extension.SetLoadbalance("random", loadbalance.NewRandomLoadBalance) failoverCluster := NewFailoverCluster() diff --git a/cluster/cluster_impl/failsafe_cluster.go b/cluster/cluster_impl/failsafe_cluster.go index f708b7fb9108bdd17fec5dc68dc1e4249c8199d4..d9465c034cb9e76d2f360b395f17b23d9234c532 100644 --- a/cluster/cluster_impl/failsafe_cluster.go +++ b/cluster/cluster_impl/failsafe_cluster.go @@ -39,6 +39,7 @@ func NewFailsafeCluster() cluster.Cluster { return &failsafeCluster{} } +// Join returns a baseClusterInvoker instance func (cluster *failsafeCluster) Join(directory cluster.Directory) protocol.Invoker { return newFailsafeClusterInvoker(directory) } diff --git a/cluster/cluster_impl/failsafe_cluster_invoker.go b/cluster/cluster_impl/failsafe_cluster_invoker.go index 4d8fe27719eb71fa287fe4142d8e92ca17acfba4..27c59fff18d4a93fc693d7edbca467e0ffef549a 100644 --- a/cluster/cluster_impl/failsafe_cluster_invoker.go +++ b/cluster/cluster_impl/failsafe_cluster_invoker.go @@ -45,6 +45,7 @@ func newFailsafeClusterInvoker(directory cluster.Directory) protocol.Invoker { } } +// nolint func (invoker *failsafeClusterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result { invokers := invoker.directory.List(invocation) diff --git a/cluster/cluster_impl/forking_cluster.go b/cluster/cluster_impl/forking_cluster.go index 0e6cd26882788a1f897d0d4dc8e0d4eb0a9d4218..8c9911327527e66864200630f5a52dd5c7b9be53 100644 --- a/cluster/cluster_impl/forking_cluster.go +++ b/cluster/cluster_impl/forking_cluster.go @@ -39,6 +39,7 @@ func NewForkingCluster() cluster.Cluster { return &forkingCluster{} } +// Join returns a baseClusterInvoker instance func (cluster *forkingCluster) Join(directory cluster.Directory) protocol.Invoker { return newForkingClusterInvoker(directory) } diff --git a/cluster/cluster_impl/forking_cluster_invoker.go b/cluster/cluster_impl/forking_cluster_invoker.go index a5a3f2ec6605dfb843fab09dff0a53000bbc3298..168444881653ca38ef61a9bc8e50f2d4bc3e624c 100644 --- a/cluster/cluster_impl/forking_cluster_invoker.go +++ b/cluster/cluster_impl/forking_cluster_invoker.go @@ -44,7 +44,7 @@ func newForkingClusterInvoker(directory cluster.Directory) protocol.Invoker { } } -// Invoke ... +// nolint func (invoker *forkingClusterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result { if err := invoker.checkWhetherDestroyed(); err != nil { return &protocol.RPCResult{Err: err} diff --git a/cluster/cluster_impl/mock_cluster.go b/cluster/cluster_impl/mock_cluster.go index d887cfb45b9c92c859b1396046c1c1c73d46b295..a7fa5d4f02087d4ec8ee0e011c09b11805f79a3f 100644 --- a/cluster/cluster_impl/mock_cluster.go +++ b/cluster/cluster_impl/mock_cluster.go @@ -33,6 +33,7 @@ func NewMockCluster() cluster.Cluster { return &mockCluster{} } +// nolint func (cluster *mockCluster) Join(directory cluster.Directory) protocol.Invoker { return protocol.NewBaseInvoker(directory.GetUrl()) } diff --git a/cluster/cluster_impl/registry_aware_cluster.go b/cluster/cluster_impl/registry_aware_cluster.go index fcefa52862a39eece98dca8660e62d9ca144e955..f4c08973713e6b3736b4ca1ed0d6e5275cf61d01 100644 --- a/cluster/cluster_impl/registry_aware_cluster.go +++ b/cluster/cluster_impl/registry_aware_cluster.go @@ -34,6 +34,7 @@ func NewRegistryAwareCluster() cluster.Cluster { return ®istryAwareCluster{} } +// nolint func (cluster *registryAwareCluster) Join(directory cluster.Directory) protocol.Invoker { return newRegistryAwareClusterInvoker(directory) } diff --git a/cluster/cluster_impl/registry_aware_cluster_invoker.go b/cluster/cluster_impl/registry_aware_cluster_invoker.go index cded5bf16432e6b0c590e15b81c28369889a5f88..7840da5218090a995298e718a4bbce9d7f5480b4 100644 --- a/cluster/cluster_impl/registry_aware_cluster_invoker.go +++ b/cluster/cluster_impl/registry_aware_cluster_invoker.go @@ -36,6 +36,7 @@ func newRegistryAwareClusterInvoker(directory cluster.Directory) protocol.Invoke } } +// nolint func (invoker *registryAwareClusterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result { invokers := invoker.directory.List(invocation) //First, pick the invoker (XXXClusterInvoker) that comes from the local registry, distinguish by a 'default' key. diff --git a/cluster/loadbalance/consistent_hash.go b/cluster/loadbalance/consistent_hash.go index 84fbb268c7a8ec32f007a734e2d6da56ef3c6d25..85eb96417c5c1f1946962a87f6b889c2ed09c26c 100644 --- a/cluster/loadbalance/consistent_hash.go +++ b/cluster/loadbalance/consistent_hash.go @@ -38,9 +38,9 @@ import ( ) const ( - // ConsistentHash ... + // ConsistentHash consistent hash ConsistentHash = "consistenthash" - // HashNodes ... + // HashNodes hash nodes HashNodes = "hash.nodes" // HashArguments key of hash arguments in url HashArguments = "hash.arguments" @@ -157,6 +157,7 @@ func (c *ConsistentHashSelector) selectForKey(hash uint32) protocol.Invoker { return c.virtualInvokers[c.keys[idx]] } +// nolint func (c *ConsistentHashSelector) hash(digest [16]byte, i int) uint32 { return uint32((digest[3+i*4]&0xFF)<<24) | uint32((digest[2+i*4]&0xFF)<<16) | uint32((digest[1+i*4]&0xFF)<<8) | uint32(digest[i*4]&0xFF)&0xFFFFFFF diff --git a/cluster/loadbalance/least_active.go b/cluster/loadbalance/least_active.go index 37ad91c3ed6b44370820a989b7af8ccaa82c48a2..87767359a94c29c9aa83ae1fa5b042d7bac2548b 100644 --- a/cluster/loadbalance/least_active.go +++ b/cluster/loadbalance/least_active.go @@ -46,6 +46,7 @@ func NewLeastActiveLoadBalance() cluster.LoadBalance { return &leastActiveLoadBalance{} } +// Select gets invoker based on least active load balancing strategy func (lb *leastActiveLoadBalance) Select(invokers []protocol.Invoker, invocation protocol.Invocation) protocol.Invoker { count := len(invokers) if count == 0 { diff --git a/cluster/loadbalance/round_robin.go b/cluster/loadbalance/round_robin.go index c44b239dbcbcc744f47ca3c97128f92567e32a78..51a76da99818063b6f13de1c007ccbc3709e1701 100644 --- a/cluster/loadbalance/round_robin.go +++ b/cluster/loadbalance/round_robin.go @@ -31,12 +31,12 @@ import ( ) const ( - // RoundRobin ... + // RoundRobin load balancing way RoundRobin = "roundrobin" - // COMPLETE ... + // nolint COMPLETE = 0 - // UPDATING ... + // nolint UPDATING = 1 ) @@ -59,6 +59,7 @@ func NewRoundRobinLoadBalance() cluster.LoadBalance { return &roundRobinLoadBalance{} } +// Select gets invoker based on round robin load balancing strategy func (lb *roundRobinLoadBalance) Select(invokers []protocol.Invoker, invocation protocol.Invocation) protocol.Invoker { count := len(invokers) if count == 0 { diff --git a/cluster/router/healthcheck/factory_test.go b/cluster/router/healthcheck/factory_test.go index c3a26a93896e185f0dea3732ca5afcf7687ad5ea..e80fd4c4d38dbb1c0f2b14ba1e22971249bc54b6 100644 --- a/cluster/router/healthcheck/factory_test.go +++ b/cluster/router/healthcheck/factory_test.go @@ -31,34 +31,43 @@ import ( "github.com/apache/dubbo-go/protocol" ) +// nolint type MockInvoker struct { url common.URL } +// nolint func NewMockInvoker(url common.URL) *MockInvoker { return &MockInvoker{ url: url, } } +// nolint func (bi *MockInvoker) GetUrl() common.URL { return bi.url } + +// nolint func (bi *MockInvoker) IsAvailable() bool { return true } +// nolint func (bi *MockInvoker) IsDestroyed() bool { return true } +// nolint func (bi *MockInvoker) Invoke(_ context.Context, _ protocol.Invocation) protocol.Result { return nil } +// nolint func (bi *MockInvoker) Destroy() { } +// nolint func TestHealthCheckRouteFactory(t *testing.T) { factory := newHealthCheckRouteFactory() assert.NotNil(t, factory) diff --git a/cluster/router/tag/tag_router.go b/cluster/router/tag/tag_router.go index 87da418943e90c63a905f35260ada7880d6f51b9..e1376fd96a88246e7ad0e26d2e3c34693c88a77c 100644 --- a/cluster/router/tag/tag_router.go +++ b/cluster/router/tag/tag_router.go @@ -31,12 +31,14 @@ import ( "github.com/apache/dubbo-go/protocol" ) +// tagRouter defines url, enable and the priority type tagRouter struct { url *common.URL enabled bool priority int64 } +// NewTagRouter returns a tagRouter instance if url is not nil func NewTagRouter(url *common.URL) (*tagRouter, error) { if url == nil { return nil, perrors.Errorf("Illegal route URL!") @@ -48,10 +50,12 @@ func NewTagRouter(url *common.URL) (*tagRouter, error) { }, nil } +// nolint func (c *tagRouter) isEnabled() bool { return c.enabled } +// Route gets a list of invoker func (c *tagRouter) Route(invokers []protocol.Invoker, url *common.URL, invocation protocol.Invocation) []protocol.Invoker { if !c.isEnabled() { return invokers @@ -62,14 +66,17 @@ func (c *tagRouter) Route(invokers []protocol.Invoker, url *common.URL, invocati return filterUsingStaticTag(invokers, url, invocation) } +// URL gets the url of tagRouter func (c *tagRouter) URL() common.URL { return *c.url } +// Priority gets the priority of tagRouter func (c *tagRouter) Priority() int64 { return c.priority } +// filterUsingStaticTag gets a list of invoker using static tag func filterUsingStaticTag(invokers []protocol.Invoker, url *common.URL, invocation protocol.Invocation) []protocol.Invoker { if tag, ok := invocation.Attachments()[constant.Tagkey]; ok { result := make([]protocol.Invoker, 0, 8) @@ -86,6 +93,7 @@ func filterUsingStaticTag(invokers []protocol.Invoker, url *common.URL, invocati return invokers } +// isForceUseTag returns whether force use tag func isForceUseTag(url *common.URL, invocation protocol.Invocation) bool { if b, e := strconv.ParseBool(invocation.AttachmentsByKey(constant.ForceUseTag, url.GetParam(constant.ForceUseTag, "false"))); e == nil { return b diff --git a/common/constant/env.go b/common/constant/env.go index 5376323328f431083a47395c9e2ebbab5b37f307..f8402b9cb8649f9471d8ae6f0d26314053496bb7 100644 --- a/common/constant/env.go +++ b/common/constant/env.go @@ -17,6 +17,7 @@ package constant +// nolint const ( // CONF_CONSUMER_FILE_PATH ... CONF_CONSUMER_FILE_PATH = "CONF_CONSUMER_FILE_PATH" diff --git a/config/base_config_test.go b/config/base_config_test.go index 15b468753ddfd99e77b3d99c0994c0599c649793..6db6a8dcb84de3fdefe94cce87338b9efe28246c 100644 --- a/config/base_config_test.go +++ b/config/base_config_test.go @@ -95,14 +95,14 @@ var baseMockRef = map[string]*ReferenceConfig{ InterfaceName: "com.MockService", Name: "GetUser", Retries: "2", - Loadbalance: "random", + LoadBalance: "random", }, { InterfaceId: "MockService", InterfaceName: "com.MockService", Name: "GetUser1", Retries: "2", - Loadbalance: "random", + LoadBalance: "random", }, }, }, @@ -258,14 +258,14 @@ func TestRefreshProvider(t *testing.T) { InterfaceName: "com.MockService", Name: "GetUser", Retries: "2", - Loadbalance: "random", + LoadBalance: "random", }, { InterfaceId: "MockService", InterfaceName: "com.MockService", Name: "GetUser1", Retries: "2", - Loadbalance: "random", + LoadBalance: "random", }, }, }, diff --git a/config/config_loader_test.go b/config/config_loader_test.go index 2cbf526a70b52f184f500bad98edb01b97d239ec..01d2ca812a278ee8fb80feb584673e2ebe470a01 100644 --- a/config/config_loader_test.go +++ b/config/config_loader_test.go @@ -278,13 +278,13 @@ func mockInitProviderWithSingleRegistry() { { Name: "GetUser", Retries: "2", - Loadbalance: "random", + LoadBalance: "random", Weight: 200, }, { Name: "GetUser1", Retries: "2", - Loadbalance: "random", + LoadBalance: "random", Weight: 200, }, }, diff --git a/config/method_config.go b/config/method_config.go index e64773eb135b2f9ec55377bded815147e2e192af..b64306fd6aa865d219506ea2722067619b00fea7 100644 --- a/config/method_config.go +++ b/config/method_config.go @@ -25,13 +25,13 @@ import ( "github.com/apache/dubbo-go/common/constant" ) -// MethodConfig ... +// MethodConfig defines method config type MethodConfig struct { InterfaceId string InterfaceName string Name string `yaml:"name" json:"name,omitempty" property:"name"` Retries string `yaml:"retries" json:"retries,omitempty" property:"retries"` - Loadbalance string `yaml:"loadbalance" json:"loadbalance,omitempty" property:"loadbalance"` + LoadBalance string `yaml:"loadbalance" json:"loadbalance,omitempty" property:"loadbalance"` Weight int64 `yaml:"weight" json:"weight,omitempty" property:"weight"` TpsLimitInterval string `yaml:"tps.limit.interval" json:"tps.limit.interval,omitempty" property:"tps.limit.interval"` TpsLimitRate string `yaml:"tps.limit.rate" json:"tps.limit.rate,omitempty" property:"tps.limit.rate"` diff --git a/config/reference_config.go b/config/reference_config.go index 748b2d403fe315f879c817c4e0a4cf3197d807da..e9a895d57a90d9fd2d5d08dcd8706e5b2d058174 100644 --- a/config/reference_config.go +++ b/config/reference_config.go @@ -220,7 +220,7 @@ func (c *ReferenceConfig) getUrlMap() url.Values { urlMap.Set(constant.REFERENCE_FILTER_KEY, mergeValue(consumerConfig.Filter, c.Filter, defaultReferenceFilter)) for _, v := range c.Methods { - urlMap.Set("methods."+v.Name+"."+constant.LOADBALANCE_KEY, v.Loadbalance) + urlMap.Set("methods."+v.Name+"."+constant.LOADBALANCE_KEY, v.LoadBalance) urlMap.Set("methods."+v.Name+"."+constant.RETRIES_KEY, v.Retries) urlMap.Set("methods."+v.Name+"."+constant.STICKY_KEY, strconv.FormatBool(v.Sticky)) if len(v.RequestTimeout) != 0 { diff --git a/config/reference_config_test.go b/config/reference_config_test.go index 3fbf8da44ca7d00e335260cf107e99dae3a2fa8a..45cdb2dfaca32f918bc067cf489a3c6fc4820dbc 100644 --- a/config/reference_config_test.go +++ b/config/reference_config_test.go @@ -103,12 +103,12 @@ func doInitConsumer() { { Name: "GetUser", Retries: "2", - Loadbalance: "random", + LoadBalance: "random", }, { Name: "GetUser1", Retries: "2", - Loadbalance: "random", + LoadBalance: "random", Sticky: true, }, }, @@ -174,12 +174,12 @@ func doInitConsumerWithSingleRegistry() { { Name: "GetUser", Retries: "2", - Loadbalance: "random", + LoadBalance: "random", }, { Name: "GetUser1", Retries: "2", - Loadbalance: "random", + LoadBalance: "random", }, }, }, diff --git a/config/service_config.go b/config/service_config.go index 57fce028fa59893979fc6f50671fe8681770a2b8..4351eea7c91d37cfaf860cd9b797730c28039305 100644 --- a/config/service_config.go +++ b/config/service_config.go @@ -303,7 +303,7 @@ func (c *ServiceConfig) getUrlMap() url.Values { for _, v := range c.Methods { prefix := "methods." + v.Name + "." - urlMap.Set(prefix+constant.LOADBALANCE_KEY, v.Loadbalance) + urlMap.Set(prefix+constant.LOADBALANCE_KEY, v.LoadBalance) urlMap.Set(prefix+constant.RETRIES_KEY, v.Retries) urlMap.Set(prefix+constant.WEIGHT_KEY, strconv.FormatInt(v.Weight, 10)) diff --git a/config/service_config_test.go b/config/service_config_test.go index e7d55077beb56b0ccf8da833f5aeebfac07a9e3f..0f7e404f6e336b8ad254e4007825ecbfcaf9d78b 100644 --- a/config/service_config_test.go +++ b/config/service_config_test.go @@ -56,13 +56,13 @@ func doInitProvider() { { Name: "GetUser", Retries: "2", - Loadbalance: "random", + LoadBalance: "random", Weight: 200, }, { Name: "GetUser1", Retries: "2", - Loadbalance: "random", + LoadBalance: "random", Weight: 200, }, }, @@ -81,13 +81,13 @@ func doInitProvider() { { Name: "GetUser", Retries: "2", - Loadbalance: "random", + LoadBalance: "random", Weight: 200, }, { Name: "GetUser1", Retries: "2", - Loadbalance: "random", + LoadBalance: "random", Weight: 200, }, }, diff --git a/config_center/apollo/factory.go b/config_center/apollo/factory.go index f975ce13d8e5832f03051c42f92157532347d283..c52d942c4f481c64d0c465cafbd6f7f8c3bb1346 100644 --- a/config_center/apollo/factory.go +++ b/config_center/apollo/factory.go @@ -34,6 +34,7 @@ func createDynamicConfigurationFactory() config_center.DynamicConfigurationFacto type apolloConfigurationFactory struct{} +// GetDynamicConfiguration gets the dynamic configuration func (f *apolloConfigurationFactory) GetDynamicConfiguration(url *common.URL) (config_center.DynamicConfiguration, error) { dynamicConfiguration, err := newApolloConfiguration(url) if err != nil { diff --git a/config_center/apollo/listener.go b/config_center/apollo/listener.go index 1cf65ed22ba0a1f765af66191ed19a04f81b0fe6..48a35093d20c445f6b6ff391f6a2e0e5b737e8f2 100644 --- a/config_center/apollo/listener.go +++ b/config_center/apollo/listener.go @@ -36,7 +36,7 @@ func NewApolloListener() *apolloListener { } } -// OnChange ... +// OnChange process each listener func (a *apolloListener) OnChange(changeEvent *agollo.ChangeEvent) { for key, change := range changeEvent.Changes { for listener := range a.listeners { diff --git a/config_center/mock_dynamic_config.go b/config_center/mock_dynamic_config.go index de208946f1715878c2afc62fdd41df93f74797c7..8fe0a251239f7bfc6a3f70c3834da1b3af8484ba 100644 --- a/config_center/mock_dynamic_config.go +++ b/config_center/mock_dynamic_config.go @@ -33,7 +33,7 @@ import ( "github.com/apache/dubbo-go/remoting" ) -// MockDynamicConfigurationFactory ... +// MockDynamicConfigurationFactory defines content type MockDynamicConfigurationFactory struct { Content string } @@ -96,7 +96,7 @@ func (c *MockDynamicConfiguration) GetConfigKeysByGroup(group string) (*gxset.Ha return gxset.NewSet(c.content), nil } -// MockDynamicConfiguration ... +// MockDynamicConfiguration uses to parse content and defines listener type MockDynamicConfiguration struct { parser parser.ConfigurationParser content string @@ -149,7 +149,7 @@ func (c *MockDynamicConfiguration) GetRule(key string, opts ...Option) (string, return c.GetProperties(key, opts...) } -// MockServiceConfigEvent ... +// MockServiceConfigEvent returns ConfiguratorConfig func (c *MockDynamicConfiguration) MockServiceConfigEvent() { config := &parser.ConfiguratorConfig{ ConfigVersion: "2.7.1", @@ -171,7 +171,7 @@ func (c *MockDynamicConfiguration) MockServiceConfigEvent() { c.listener[key].Process(&ConfigChangeEvent{Key: key, Value: string(value), ConfigType: remoting.EventTypeAdd}) } -// MockApplicationConfigEvent ... +// MockApplicationConfigEvent returns ConfiguratorConfig func (c *MockDynamicConfiguration) MockApplicationConfigEvent() { config := &parser.ConfiguratorConfig{ ConfigVersion: "2.7.1", diff --git a/config_center/parser/configuration_parser.go b/config_center/parser/configuration_parser.go index 6fbdc27d4339150bfec624f7dc5ea0f6a608d7a7..f794221f9cf3c689d52b32a57ab51f7908f17297 100644 --- a/config_center/parser/configuration_parser.go +++ b/config_center/parser/configuration_parser.go @@ -35,13 +35,13 @@ import ( ) const ( - // ScopeApplication ... + // ScopeApplication : scope application ScopeApplication = "application" - // GeneralType ... + // GeneralType defines the general type GeneralType = "general" ) -// ConfigurationParser ... +// ConfigurationParser interface type ConfigurationParser interface { Parse(string) (map[string]string, error) ParseToUrls(content string) ([]*common.URL, error) @@ -50,7 +50,7 @@ type ConfigurationParser interface { // DefaultConfigurationParser for supporting properties file in config center type DefaultConfigurationParser struct{} -// ConfiguratorConfig ... +// ConfiguratorConfig defines configurator config type ConfiguratorConfig struct { ConfigVersion string `yaml:"configVersion"` Scope string `yaml:"scope"` @@ -59,7 +59,7 @@ type ConfiguratorConfig struct { Configs []ConfigItem `yaml:"configs"` } -// ConfigItem ... +// ConfigItem defines config item type ConfigItem struct { Type string `yaml:"type"` Enabled bool `yaml:"enabled"` @@ -81,7 +81,7 @@ func (parser *DefaultConfigurationParser) Parse(content string) (map[string]stri return pps.Map(), nil } -// ParseToUrls ... +// ParseToUrls is used to parse content to urls func (parser *DefaultConfigurationParser) ParseToUrls(content string) ([]*common.URL, error) { config := ConfiguratorConfig{} if err := yaml.Unmarshal([]byte(content), &config); err != nil { @@ -110,6 +110,7 @@ func (parser *DefaultConfigurationParser) ParseToUrls(content string) ([]*common return allUrls, nil } +// serviceItemToUrls is used to transfer item and config to urls func serviceItemToUrls(item ConfigItem, config ConfiguratorConfig) ([]*common.URL, error) { var addresses = item.Addresses if len(addresses) == 0 { @@ -156,6 +157,7 @@ func serviceItemToUrls(item ConfigItem, config ConfiguratorConfig) ([]*common.UR return urls, nil } +// nolint func appItemToUrls(item ConfigItem, config ConfiguratorConfig) ([]*common.URL, error) { var addresses = item.Addresses if len(addresses) == 0 { @@ -196,6 +198,7 @@ func appItemToUrls(item ConfigItem, config ConfiguratorConfig) ([]*common.URL, e return urls, nil } +// getServiceString returns service string func getServiceString(service string) (string, error) { if len(service) == 0 { return "", perrors.New("service field in configuration is null.") @@ -219,6 +222,7 @@ func getServiceString(service string) (string, error) { return serviceStr, nil } +// nolint func getParamString(item ConfigItem) (string, error) { var retStr string retStr = retStr + "category=" @@ -241,6 +245,7 @@ func getParamString(item ConfigItem) (string, error) { return retStr, nil } +// getEnabledString returns enabled string func getEnabledString(item ConfigItem, config ConfiguratorConfig) string { retStr := "&enabled=" if len(item.Type) == 0 || item.Type == GeneralType { diff --git a/config_center/zookeeper/listener.go b/config_center/zookeeper/listener.go index 747c4be352add3f549eaf02e83da6442a8a84c6a..bc6eb6d6eec4413515228a712cd11810e11f08cc 100644 --- a/config_center/zookeeper/listener.go +++ b/config_center/zookeeper/listener.go @@ -27,7 +27,7 @@ import ( "github.com/apache/dubbo-go/remoting" ) -// CacheListener ... +// CacheListener defines keyListeners and rootPath type CacheListener struct { keyListeners sync.Map rootPath string diff --git a/filter/filter.go b/filter/filter.go index d20ca72c345c6812f4bce6df5dbaf683429a9874..804bf3b9df8040c6377648f150c25d421b29b93d 100644 --- a/filter/filter.go +++ b/filter/filter.go @@ -27,7 +27,7 @@ import ( // Filter interface defines the functions of a filter // Extension - Filter type Filter interface { - // Invoke is the core function of a filter, it determins the process of the filter + // Invoke is the core function of a filter, it determines the process of the filter Invoke(context.Context, protocol.Invoker, protocol.Invocation) protocol.Result // OnResponse updates the results from Invoke and then returns the modified results. OnResponse(context.Context, protocol.Result, protocol.Invoker, protocol.Invocation) protocol.Result diff --git a/filter/filter_impl/access_log_filter.go b/filter/filter_impl/access_log_filter.go index 49cdc2287c28ae0cbbd0fcab3700536595bb0f5e..621012c24c0ad12b3bda397148a3ed9c29d080ed 100644 --- a/filter/filter_impl/access_log_filter.go +++ b/filter/filter_impl/access_log_filter.go @@ -36,20 +36,20 @@ import ( const ( //used in URL. - // FileDateFormat ... + // nolint FileDateFormat = "2006-01-02" - // MessageDateLayout ... + // nolint MessageDateLayout = "2006-01-02 15:04:05" - // LogMaxBuffer ... + // nolint LogMaxBuffer = 5000 - // LogFileMode ... + // nolint LogFileMode = 0600 // those fields are the data collected by this filter - // Types ... + // nolint Types = "types" - // Arguments ... + // nolint Arguments = "arguments" ) diff --git a/filter/filter_impl/echo_filter.go b/filter/filter_impl/echo_filter.go index 7da5ec7029ea698b1bf1a14ad36123fbec3aacf7..24ba6e47acbffd28eedfffcd0dbaf9717e222946 100644 --- a/filter/filter_impl/echo_filter.go +++ b/filter/filter_impl/echo_filter.go @@ -65,7 +65,7 @@ func (ef *EchoFilter) OnResponse(_ context.Context, result protocol.Result, _ pr return result } -// GetFilter ... +// GetFilter gets the Filter func GetFilter() filter.Filter { return &EchoFilter{} } diff --git a/filter/filter_impl/execute_limit_filter.go b/filter/filter_impl/execute_limit_filter.go index bfc5096ca089867f6e6234089e387d3f9b48a3aa..5fc309cfb49fbeef5e933a84c1b80654087da701 100644 --- a/filter/filter_impl/execute_limit_filter.go +++ b/filter/filter_impl/execute_limit_filter.go @@ -74,7 +74,7 @@ type ExecuteLimitFilter struct { executeState *concurrent.Map } -// ExecuteState ... +// ExecuteState defines the concurrent count type ExecuteState struct { concurrentCount int64 } diff --git a/filter/filter_impl/generic_filter.go b/filter/filter_impl/generic_filter.go index 3f4d714e6b0cbdf48f5e1afce3222a18857041f9..d385054ed98518177aea5e574e034cb35c72e398 100644 --- a/filter/filter_impl/generic_filter.go +++ b/filter/filter_impl/generic_filter.go @@ -47,7 +47,7 @@ func init() { // when do a generic invoke, struct need to be map -// GenericFilter ... +// nolint type GenericFilter struct{} // Invoke turns the parameters to map for generic method diff --git a/filter/filter_impl/generic_service_filter.go b/filter/filter_impl/generic_service_filter.go index 6272df6b39b0c18a77721f3a8c9e92618133aa6c..3711e68cce67dacfec074a5e44c080a629bce305 100644 --- a/filter/filter_impl/generic_service_filter.go +++ b/filter/filter_impl/generic_service_filter.go @@ -40,9 +40,9 @@ import ( ) const ( - // GENERIC_SERVICE ... + // GENERIC_SERVICE defines the filter name GENERIC_SERVICE = "generic_service" - // GENERIC_SERIALIZATION_DEFAULT ... + // nolint GENERIC_SERIALIZATION_DEFAULT = "true" ) @@ -50,10 +50,10 @@ func init() { extension.SetFilter(GENERIC_SERVICE, GetGenericServiceFilter) } -// GenericServiceFilter ... +// nolint type GenericServiceFilter struct{} -// Invoke ... +// Invoke is used to call service method by invocation func (ef *GenericServiceFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result { logger.Infof("invoking generic service filter.") logger.Debugf("generic service filter methodName:%v,args:%v", invocation.MethodName(), len(invocation.Arguments())) @@ -115,7 +115,7 @@ func (ef *GenericServiceFilter) Invoke(ctx context.Context, invoker protocol.Inv return invoker.Invoke(ctx, newInvocation) } -// OnResponse ... +// nolint func (ef *GenericServiceFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result { if invocation.MethodName() == constant.GENERIC && len(invocation.Arguments()) == 3 && result.Result() != nil { v := reflect.ValueOf(result.Result()) @@ -127,7 +127,7 @@ func (ef *GenericServiceFilter) OnResponse(ctx context.Context, result protocol. return result } -// GetGenericServiceFilter ... +// nolint func GetGenericServiceFilter() filter.Filter { return &GenericServiceFilter{} } diff --git a/filter/filter_impl/generic_service_filter_test.go b/filter/filter_impl/generic_service_filter_test.go index f0bdb7fb334f31de27d32d79124e4cb8c03f45a0..67819717cf07383373f905ed9420a42cc0bfddb9 100644 --- a/filter/filter_impl/generic_service_filter_test.go +++ b/filter/filter_impl/generic_service_filter_test.go @@ -51,7 +51,7 @@ func (c *TestStruct) JavaClassName() string { type TestService struct{} -// MethodOne ... +// nolint func (ts *TestService) MethodOne(_ context.Context, test1 *TestStruct, test2 []TestStruct, test3 interface{}, test4 []interface{}, test5 *string) (*TestStruct, error) { if test1 == nil { @@ -72,7 +72,7 @@ func (ts *TestService) MethodOne(_ context.Context, test1 *TestStruct, test2 []T return &TestStruct{}, nil } -// Reference ... +// nolint func (*TestService) Reference() string { return "com.test.Path" } diff --git a/filter/filter_impl/hystrix_filter.go b/filter/filter_impl/hystrix_filter.go index 711ef71c44192c5a1d76783a3b3d4cbd0b97632c..e2275149f1229c87ed4ae3f89dc9ae32d9fe6461 100644 --- a/filter/filter_impl/hystrix_filter.go +++ b/filter/filter_impl/hystrix_filter.go @@ -37,11 +37,11 @@ import ( ) const ( - // HYSTRIX_CONSUMER ... + // nolint HYSTRIX_CONSUMER = "hystrix_consumer" - // HYSTRIX_PROVIDER ... + // nolint HYSTRIX_PROVIDER = "hystrix_provider" - // HYSTRIX ... + // nolint HYSTRIX = "hystrix" ) @@ -85,14 +85,14 @@ func NewHystrixFilterError(err error, failByHystrix bool) error { } } -// HystrixFilter ... +// nolint type HystrixFilter struct { COrP bool //true for consumer res map[string][]*regexp.Regexp ifNewMap sync.Map } -// Invoke is an implentation of filter, provides Hystrix pattern latency and fault tolerance +// Invoke is an implementation of filter, provides Hystrix pattern latency and fault tolerance func (hf *HystrixFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result { cmdName := fmt.Sprintf("%s&method=%s", invoker.GetUrl().Key(), invocation.MethodName()) @@ -256,7 +256,7 @@ func initHystrixConfigProvider() error { // return initHystrixConfig() //} -// CommandConfigWithError ... +// nolint type CommandConfigWithError struct { Timeout int `yaml:"timeout"` MaxConcurrentRequests int `yaml:"max_concurrent_requests"` @@ -274,14 +274,14 @@ type CommandConfigWithError struct { //- ErrorPercentThreshold: it causes circuits to open once the rolling measure of errors exceeds this percent of requests //See hystrix doc -// HystrixFilterConfig ... +// nolint type HystrixFilterConfig struct { Configs map[string]*CommandConfigWithError Default string Services map[string]ServiceHystrixConfig } -// ServiceHystrixConfig ... +// nolint type ServiceHystrixConfig struct { ServiceConfig string `yaml:"service_config"` Methods map[string]string diff --git a/filter/filter_impl/token_filter.go b/filter/filter_impl/token_filter.go index 23742c66e94d9ecfc09d004441a54aad86ef049e..fe4e38747ed10a40950c87747220339d0d566781 100644 --- a/filter/filter_impl/token_filter.go +++ b/filter/filter_impl/token_filter.go @@ -34,7 +34,7 @@ import ( ) const ( - // TOKEN ... + // nolint TOKEN = "token" ) @@ -66,7 +66,7 @@ func (tf *TokenFilter) OnResponse(ctx context.Context, result protocol.Result, i return result } -// GetTokenFilter ... +// nolint func GetTokenFilter() filter.Filter { return &TokenFilter{} } diff --git a/filter/filter_impl/tps/tps_limit_fix_window_strategy.go b/filter/filter_impl/tps/tps_limit_fix_window_strategy.go index 7419a4576122d4db334969b0711666b5b2816e60..d495e035de521612cc9b85ec9e817ae3355a818b 100644 --- a/filter/filter_impl/tps/tps_limit_fix_window_strategy.go +++ b/filter/filter_impl/tps/tps_limit_fix_window_strategy.go @@ -29,7 +29,7 @@ import ( ) const ( - // FixedWindowKey ... + // FixedWindowKey defines tps limit algorithm FixedWindowKey = "fixedWindow" ) diff --git a/filter/filter_impl/tps/tps_limit_strategy_mock.go b/filter/filter_impl/tps/tps_limit_strategy_mock.go index c228c7349ce6ad305051e0ba9b26dddee8c12c71..be76466092b48022330a6fb35ba99bbf0d03134e 100644 --- a/filter/filter_impl/tps/tps_limit_strategy_mock.go +++ b/filter/filter_impl/tps/tps_limit_strategy_mock.go @@ -23,6 +23,9 @@ package tps import ( gomock "github.com/golang/mock/gomock" +) + +import ( reflect "reflect" ) diff --git a/filter/filter_impl/tracing_filter_test.go b/filter/filter_impl/tracing_filter_test.go index 15dc32e7ec1d30936b37ab2350c899e5c30d2ab7..57f4095d49be784d7688d2acf17c1ea0225d0000 100644 --- a/filter/filter_impl/tracing_filter_test.go +++ b/filter/filter_impl/tracing_filter_test.go @@ -26,12 +26,9 @@ import ( "github.com/opentracing/opentracing-go" ) -import ( - "github.com/apache/dubbo-go/common/constant" -) - import ( "github.com/apache/dubbo-go/common" + "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/protocol" "github.com/apache/dubbo-go/protocol/invocation" ) diff --git a/go.mod b/go.mod index e82a04b279ef16297d029b2a3993b5327b23c804..a16b9062257ef13da565cc594e7385e0fdb17c17 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,7 @@ module github.com/apache/dubbo-go require ( github.com/Workiva/go-datastructures v1.0.50 github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 - github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190307165228-86c17b95fcd5 // indirect github.com/apache/dubbo-go-hessian2 v1.6.1 - github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect github.com/coreos/bbolt v1.3.3 // indirect github.com/coreos/etcd v3.3.13+incompatible github.com/coreos/go-semver v0.3.0 // indirect diff --git a/metadata/service/exporter/configurable/exporter_test.go b/metadata/service/exporter/configurable/exporter_test.go index 4689c6660b7da78609501c5e98f0dd309e4bce7f..9fdbd76757815af0aa975ec6e5f1b20fa5f1a83e 100644 --- a/metadata/service/exporter/configurable/exporter_test.go +++ b/metadata/service/exporter/configurable/exporter_test.go @@ -97,13 +97,13 @@ func mockInitProviderWithSingleRegistry() { { Name: "GetUser", Retries: "2", - Loadbalance: "random", + LoadBalance: "random", Weight: 200, }, { Name: "GetUser1", Retries: "2", - Loadbalance: "random", + LoadBalance: "random", Weight: 200, }, }, diff --git a/protocol/dubbo/codec.go b/protocol/dubbo/codec.go index 1f7d107544a06d0ef83bcb54ff6f03daf2dc517b..8ba725e3cebd8261bc0adeea0e6fb8ef53f383a0 100644 --- a/protocol/dubbo/codec.go +++ b/protocol/dubbo/codec.go @@ -54,10 +54,10 @@ const ( // dubbo package //////////////////////////////////////////// -// SequenceType ... +// SequenceType sequence type type SequenceType int64 -// DubboPackage ... +// nolint type DubboPackage struct { Header hessian.DubboHeader Service hessian.Service @@ -82,7 +82,7 @@ func (p *DubboPackage) Marshal() (*bytes.Buffer, error) { return bytes.NewBuffer(pkg), nil } -// Unmarshal dncode hessian package. +// Unmarshal decode hessian package. func (p *DubboPackage) Unmarshal(buf *bytes.Buffer, opts ...interface{}) error { // fix issue https://github.com/apache/dubbo-go/issues/380 bufLen := buf.Len() diff --git a/protocol/grpc/grpc_exporter.go b/protocol/grpc/grpc_exporter.go index 79962b59e29bb0e3aeb58776f6c26abc2e6832de..0dc764854d61576892800180041c53f0a7735c7c 100644 --- a/protocol/grpc/grpc_exporter.go +++ b/protocol/grpc/grpc_exporter.go @@ -28,7 +28,7 @@ import ( "github.com/apache/dubbo-go/protocol" ) -// GrpcExporter ... +// nolint type GrpcExporter struct { *protocol.BaseExporter } diff --git a/protocol/grpc/grpc_invoker.go b/protocol/grpc/grpc_invoker.go index e150d05e6fb39890bd3e355f4042b4ef34db42ed..737e8c40a063b07e56d7c90f7de04670461ce103 100644 --- a/protocol/grpc/grpc_invoker.go +++ b/protocol/grpc/grpc_invoker.go @@ -37,14 +37,14 @@ import ( var errNoReply = errors.New("request need @response") -// GrpcInvoker ... +// nolint type GrpcInvoker struct { protocol.BaseInvoker quitOnce sync.Once client *Client } -// NewGrpcInvoker ... +// NewGrpcInvoker returns a Grpc invoker instance func NewGrpcInvoker(url common.URL, client *Client) *GrpcInvoker { return &GrpcInvoker{ BaseInvoker: *protocol.NewBaseInvoker(url), @@ -52,7 +52,7 @@ func NewGrpcInvoker(url common.URL, client *Client) *GrpcInvoker { } } -// Invoke ... +// Invoke is used to call service method by invocation func (gi *GrpcInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result { var ( result protocol.RPCResult @@ -81,17 +81,17 @@ func (gi *GrpcInvoker) Invoke(ctx context.Context, invocation protocol.Invocatio return &result } -// IsAvailable ... +// IsAvailable get available status func (gi *GrpcInvoker) IsAvailable() bool { return gi.BaseInvoker.IsAvailable() && gi.client.GetState() != connectivity.Shutdown } -// IsDestroyed ... +// IsDestroyed get destroyed status func (gi *GrpcInvoker) IsDestroyed() bool { return gi.BaseInvoker.IsDestroyed() && gi.client.GetState() == connectivity.Shutdown } -// Destroy ... +// Destroy will destroy gRPC's invoker and client, so it is only called once func (gi *GrpcInvoker) Destroy() { gi.quitOnce.Do(func() { gi.BaseInvoker.Destroy() diff --git a/protocol/jsonrpc/http.go b/protocol/jsonrpc/http.go index 5fca66d99399b2974f858cbedb31d9615a303637..2a2ddfeeeb52b865e96ccff69d2b39d8a671ed41 100644 --- a/protocol/jsonrpc/http.go +++ b/protocol/jsonrpc/http.go @@ -47,7 +47,7 @@ import ( // Request // //////////////////////////////////////////// -// Request ... +// Request is HTTP protocol request type Request struct { ID int64 group string diff --git a/protocol/jsonrpc/json.go b/protocol/jsonrpc/json.go index 7b05a229437958b44a405780bbe1649a995478d0..506c4c953b1b1113b43669171efdeeaeb6fca10d 100644 --- a/protocol/jsonrpc/json.go +++ b/protocol/jsonrpc/json.go @@ -288,7 +288,7 @@ type ServerCodec struct { var ( null = json.RawMessage([]byte("null")) - // Version ... + // Version is json RPC's version Version = "2.0" ) diff --git a/protocol/protocolwrapper/protocol_filter_wrapper.go b/protocol/protocolwrapper/protocol_filter_wrapper.go index cba1d5d5bce8c3de387381d17cc3f7965bf3adac..87f90d3b7c73328a30e883da8251ac8364a63b2d 100644 --- a/protocol/protocolwrapper/protocol_filter_wrapper.go +++ b/protocol/protocolwrapper/protocol_filter_wrapper.go @@ -86,7 +86,7 @@ func buildInvokerChain(invoker protocol.Invoker, key string) protocol.Invoker { return next } -// GetProtocol ... +// nolint func GetProtocol() protocol.Protocol { return &ProtocolFilterWrapper{} } @@ -95,30 +95,30 @@ func GetProtocol() protocol.Protocol { // filter invoker /////////////////////////// -// FilterInvoker ... +// FilterInvoker defines invoker and filter type FilterInvoker struct { next protocol.Invoker invoker protocol.Invoker filter filter.Filter } -// GetUrl ... +// GetUrl is used to get url from FilterInvoker func (fi *FilterInvoker) GetUrl() common.URL { return fi.invoker.GetUrl() } -// IsAvailable ... +// IsAvailable is used to get available status func (fi *FilterInvoker) IsAvailable() bool { return fi.invoker.IsAvailable() } -// Invoke ... +// Invoke is used to call service method by invocation func (fi *FilterInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result { result := fi.filter.Invoke(ctx, fi.next, invocation) return fi.filter.OnResponse(ctx, result, fi.invoker, invocation) } -// Destroy ... +// Destroy will destroy invoker func (fi *FilterInvoker) Destroy() { fi.invoker.Destroy() } diff --git a/protocol/rest/config/rest_config.go b/protocol/rest/config/rest_config.go index 168ec8ce525fc7fd5d4a30d4f11ba7bf42d1c921..4732dd8e4eae3ba874fdd8ed95380e6ace3ab66d 100644 --- a/protocol/rest/config/rest_config.go +++ b/protocol/rest/config/rest_config.go @@ -26,7 +26,7 @@ var ( restProviderServiceConfigMap map[string]*RestServiceConfig ) -// RestConsumerConfig ... +// nolint type RestConsumerConfig struct { Client string `default:"resty" yaml:"rest_client" json:"rest_client,omitempty" property:"rest_client"` Produces string `default:"application/json" yaml:"rest_produces" json:"rest_produces,omitempty" property:"rest_produces"` @@ -34,7 +34,7 @@ type RestConsumerConfig struct { RestServiceConfigsMap map[string]*RestServiceConfig `yaml:"references" json:"references,omitempty" property:"references"` } -// UnmarshalYAML ... +// UnmarshalYAML unmarshals the RestConsumerConfig by @unmarshal function func (c *RestConsumerConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { if err := defaults.Set(c); err != nil { return err @@ -46,7 +46,7 @@ func (c *RestConsumerConfig) UnmarshalYAML(unmarshal func(interface{}) error) er return nil } -// RestProviderConfig ... +// nolint type RestProviderConfig struct { Server string `default:"go-restful" yaml:"rest_server" json:"rest_server,omitempty" property:"rest_server"` Produces string `default:"*/*" yaml:"rest_produces" json:"rest_produces,omitempty" property:"rest_produces"` @@ -54,7 +54,7 @@ type RestProviderConfig struct { RestServiceConfigsMap map[string]*RestServiceConfig `yaml:"services" json:"services,omitempty" property:"services"` } -// UnmarshalYAML ... +// UnmarshalYAML unmarshals the RestProviderConfig by @unmarshal function func (c *RestProviderConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { if err := defaults.Set(c); err != nil { return err @@ -66,7 +66,7 @@ func (c *RestProviderConfig) UnmarshalYAML(unmarshal func(interface{}) error) er return nil } -// RestServiceConfig ... +// nolint type RestServiceConfig struct { InterfaceName string `required:"true" yaml:"interface" json:"interface,omitempty" property:"interface"` Url string `yaml:"url" json:"url,omitempty" property:"url"` @@ -80,7 +80,7 @@ type RestServiceConfig struct { RestMethodConfigsMap map[string]*RestMethodConfig } -// UnmarshalYAML ... +// UnmarshalYAML unmarshals the RestServiceConfig by @unmarshal function func (c *RestServiceConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { if err := defaults.Set(c); err != nil { return err @@ -92,7 +92,7 @@ func (c *RestServiceConfig) UnmarshalYAML(unmarshal func(interface{}) error) err return nil } -// RestMethodConfig ... +// nolint type RestMethodConfig struct { InterfaceName string MethodName string `required:"true" yaml:"name" json:"name,omitempty" property:"name"` @@ -110,7 +110,7 @@ type RestMethodConfig struct { HeadersMap map[int]string } -// UnmarshalYAML ... +// UnmarshalYAML unmarshals the RestMethodConfig by @unmarshal function func (c *RestMethodConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { if err := defaults.Set(c); err != nil { return err @@ -122,32 +122,32 @@ func (c *RestMethodConfig) UnmarshalYAML(unmarshal func(interface{}) error) erro return nil } -// GetRestConsumerServiceConfig ... +// nolint func GetRestConsumerServiceConfig(path string) *RestServiceConfig { return restConsumerServiceConfigMap[path] } -// GetRestProviderServiceConfig ... +// nolint func GetRestProviderServiceConfig(path string) *RestServiceConfig { return restProviderServiceConfigMap[path] } -// SetRestConsumerServiceConfigMap ... +// nolint func SetRestConsumerServiceConfigMap(configMap map[string]*RestServiceConfig) { restConsumerServiceConfigMap = configMap } -// SetRestProviderServiceConfigMap ... +// nolint func SetRestProviderServiceConfigMap(configMap map[string]*RestServiceConfig) { restProviderServiceConfigMap = configMap } -// GetRestConsumerServiceConfigMap ... +// nolint func GetRestConsumerServiceConfigMap() map[string]*RestServiceConfig { return restConsumerServiceConfigMap } -// GetRestProviderServiceConfigMap ... +// nolint func GetRestProviderServiceConfigMap() map[string]*RestServiceConfig { return restProviderServiceConfigMap } diff --git a/protocol/rest/rest_exporter.go b/protocol/rest/rest_exporter.go index 1ee208615ea07e3f2850920492ab9e9821e7ffef..e39558caeae9811817cc26a1717c1b8e3729234c 100644 --- a/protocol/rest/rest_exporter.go +++ b/protocol/rest/rest_exporter.go @@ -28,16 +28,19 @@ import ( "github.com/apache/dubbo-go/protocol" ) +// nolint type RestExporter struct { protocol.BaseExporter } +// NewRestExporter returns a RestExporter func NewRestExporter(key string, invoker protocol.Invoker, exporterMap *sync.Map) *RestExporter { return &RestExporter{ BaseExporter: *protocol.NewBaseExporter(key, invoker, exporterMap), } } +// Unexport unexport the RestExporter func (re *RestExporter) Unexport() { serviceId := re.GetInvoker().GetUrl().GetParam(constant.BEAN_NAME_KEY, "") interfaceName := re.GetInvoker().GetUrl().GetParam(constant.INTERFACE_KEY, "") diff --git a/protocol/rest/rest_invoker.go b/protocol/rest/rest_invoker.go index 121d1217efd3baea0f961b67e243e9a0450aefc2..691beeda4085f316075fe55b9328bc86d6328187 100644 --- a/protocol/rest/rest_invoker.go +++ b/protocol/rest/rest_invoker.go @@ -35,12 +35,14 @@ import ( "github.com/apache/dubbo-go/protocol/rest/config" ) +// nolint type RestInvoker struct { protocol.BaseInvoker client client.RestClient restMethodConfigMap map[string]*config.RestMethodConfig } +// NewRestInvoker returns a RestInvoker func NewRestInvoker(url common.URL, client *client.RestClient, restMethodConfig map[string]*config.RestMethodConfig) *RestInvoker { return &RestInvoker{ BaseInvoker: *protocol.NewBaseInvoker(url), @@ -49,6 +51,7 @@ func NewRestInvoker(url common.URL, client *client.RestClient, restMethodConfig } } +// Invoke is used to call service method by invocation func (ri *RestInvoker) Invoke(ctx context.Context, invocation protocol.Invocation) protocol.Result { inv := invocation.(*invocation_impl.RPCInvocation) methodConfig := ri.restMethodConfigMap[inv.MethodName()] @@ -95,6 +98,7 @@ func (ri *RestInvoker) Invoke(ctx context.Context, invocation protocol.Invocatio return &result } +// restStringMapTransform is used to transform rest map func restStringMapTransform(paramsMap map[int]string, args []interface{}) (map[string]string, error) { resMap := make(map[string]string, len(paramsMap)) for k, v := range paramsMap { @@ -106,6 +110,7 @@ func restStringMapTransform(paramsMap map[int]string, args []interface{}) (map[s return resMap, nil } +// nolint func getRestHttpHeader(methodConfig *config.RestMethodConfig, args []interface{}) (http.Header, error) { header := http.Header{} headersMap := methodConfig.HeadersMap diff --git a/protocol/rest/rest_protocol.go b/protocol/rest/rest_protocol.go index e15eeb39d72212eb9f1d0235313eba231d3b0a36..0cd26c240a7eb1b83a04ca2f57c332bbda994967 100644 --- a/protocol/rest/rest_protocol.go +++ b/protocol/rest/rest_protocol.go @@ -44,10 +44,12 @@ var ( const REST = "rest" +// nolint func init() { extension.SetProtocol(REST, GetRestProtocol) } +// nolint type RestProtocol struct { protocol.BaseProtocol serverLock sync.Mutex @@ -56,6 +58,7 @@ type RestProtocol struct { clientMap map[client.RestOptions]client.RestClient } +// NewRestProtocol returns a RestProtocol func NewRestProtocol() *RestProtocol { return &RestProtocol{ BaseProtocol: protocol.NewBaseProtocol(), @@ -64,6 +67,7 @@ func NewRestProtocol() *RestProtocol { } } +// Export export rest service func (rp *RestProtocol) Export(invoker protocol.Invoker) protocol.Exporter { url := invoker.GetUrl() serviceKey := url.ServiceKey() @@ -81,6 +85,7 @@ func (rp *RestProtocol) Export(invoker protocol.Invoker) protocol.Exporter { return exporter } +// Refer create rest service reference func (rp *RestProtocol) Refer(url common.URL) protocol.Invoker { // create rest_invoker var requestTimeout = config.GetConsumerConfig().RequestTimeout @@ -101,6 +106,7 @@ func (rp *RestProtocol) Refer(url common.URL) protocol.Invoker { return invoker } +// nolint func (rp *RestProtocol) getServer(url common.URL, serverType string) server.RestServer { restServer, ok := rp.serverMap[url.Location] if ok { @@ -122,6 +128,7 @@ func (rp *RestProtocol) getServer(url common.URL, serverType string) server.Rest return restServer } +// nolint func (rp *RestProtocol) getClient(restOptions client.RestOptions, clientType string) client.RestClient { restClient, ok := rp.clientMap[restOptions] if ok { @@ -138,6 +145,7 @@ func (rp *RestProtocol) getClient(restOptions client.RestOptions, clientType str return restClient } +// Destroy destroy rest service func (rp *RestProtocol) Destroy() { // destroy rest_server rp.BaseProtocol.Destroy() @@ -150,6 +158,7 @@ func (rp *RestProtocol) Destroy() { } } +// GetRestProtocol get a rest protocol func GetRestProtocol() protocol.Protocol { if restProtocol == nil { restProtocol = NewRestProtocol() diff --git a/registry/servicediscovery/synthesizer/subscribed_urls_synthesizer.go b/registry/servicediscovery/synthesizer/subscribed_urls_synthesizer.go index 949a5822c237de413b59d35efe94f807975795cf..415ca35fbad2fa335d687dc7a7718fa3a4b2b487 100644 --- a/registry/servicediscovery/synthesizer/subscribed_urls_synthesizer.go +++ b/registry/servicediscovery/synthesizer/subscribed_urls_synthesizer.go @@ -22,6 +22,7 @@ import ( "github.com/apache/dubbo-go/registry" ) +// SubscribedURLsSynthesizer is used to synthesize the subscribed url type SubscribedURLsSynthesizer interface { // Supports the synthesis of the subscribed url or not Support(subscribedURL *common.URL) bool diff --git a/remoting/listener.go b/remoting/listener.go index 6cbb883181ff8ec1c9124f8d8cc3d7ec0920abd9..eb27c71dfd64a1063927663a9817f8f23b85dd20 100644 --- a/remoting/listener.go +++ b/remoting/listener.go @@ -48,6 +48,7 @@ var serviceEventTypeStrings = [...]string{ "update", } +// nolint func (t EventType) String() string { return serviceEventTypeStrings[t] } @@ -63,6 +64,7 @@ type Event struct { Content string } +// nolint func (e Event) String() string { return fmt.Sprintf("Event{Action{%s}, Content{%s}}", e.Action, e.Content) }