You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/06/07 02:45:37 UTC
[dubbo-go] branch 3.0 updated: fix type; remove useless code (#1243)
This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/3.0 by this push:
new 7ef3eff fix type; remove useless code (#1243)
7ef3eff is described below
commit 7ef3eff3cc00fd3c339d1d49119c5da9f94d6dd4
Author: gaoxinge <xg...@tianrang-inc.com>
AuthorDate: Mon Jun 7 10:45:29 2021 +0800
fix type; remove useless code (#1243)
* fix type; remove useless code
* log
---
common/logger/logger.go | 3 +--
config/base_config.go | 3 ---
config/base_config_test.go | 1 -
config/config_api.go | 19 +++++++++----------
config/config_center_config.go | 2 --
config/config_loader.go | 8 ++++----
config/config_loader_options.go | 5 ++++-
config/config_loader_test.go | 16 ++++++++--------
config/consumer_config.go | 4 ----
config/graceful_shutdown_test.go | 1 -
config/metadata_report_config_test.go | 8 +++++---
config/provider_config.go | 4 ----
config/reference_config.go | 6 ++----
config/registry_config.go | 6 +-----
config/service_config.go | 5 +----
config/service_config_test.go | 3 +--
metadata/service/exporter/configurable/exporter.go | 3 +--
17 files changed, 37 insertions(+), 60 deletions(-)
diff --git a/common/logger/logger.go b/common/logger/logger.go
index 3679575..0aa7410 100644
--- a/common/logger/logger.go
+++ b/common/logger/logger.go
@@ -20,7 +20,6 @@ package logger
import (
"flag"
"io/ioutil"
- "log"
"os"
"path"
)
@@ -75,7 +74,7 @@ func init() {
}
err := InitLog(*logConfFile)
if err != nil {
- log.Printf("[InitLog] warn: %v", err)
+ logger.Warnf("InitLog with error %v", err)
}
}
diff --git a/config/base_config.go b/config/base_config.go
index bdf7135..bd22ec8 100644
--- a/config/base_config.go
+++ b/config/base_config.go
@@ -224,8 +224,6 @@ func setFieldValue(val reflect.Value, id reflect.Value, config *config.InmemoryC
}
- // iter := f.MapRange()
-
for _, k := range f.MapKeys() {
v := f.MapIndex(k)
switch v.Kind() {
@@ -244,7 +242,6 @@ func setFieldValue(val reflect.Value, id reflect.Value, config *config.InmemoryC
}
}
setBaseValue(f)
-
}
}
}
diff --git a/config/base_config_test.go b/config/base_config_test.go
index 9ef0d25..7d5fa55 100644
--- a/config/base_config_test.go
+++ b/config/base_config_test.go
@@ -27,7 +27,6 @@ import (
import (
"dubbo.apache.org/dubbo-go/v3/common/config"
- _ "dubbo.apache.org/dubbo-go/v3/config_center/apollo"
)
func getMockMap() map[string]string {
diff --git a/config/config_api.go b/config/config_api.go
index eac5a79..404f2e9 100644
--- a/config/config_api.go
+++ b/config/config_api.go
@@ -18,7 +18,6 @@
package config
import (
- "context"
"time"
)
@@ -259,7 +258,7 @@ type ReferenceConfigOpt func(config *ReferenceConfig) *ReferenceConfig
// NewDefaultReferenceConfig returns empty ReferenceConfig
func NewDefaultReferenceConfig() *ReferenceConfig {
- newReferenceConfig := NewReferenceConfig("", context.Background())
+ newReferenceConfig := NewReferenceConfig("")
newReferenceConfig.Methods = make([]*MethodConfig, 0, 8)
newReferenceConfig.Params = make(map[string]string, 8)
return newReferenceConfig
@@ -267,11 +266,11 @@ func NewDefaultReferenceConfig() *ReferenceConfig {
// NewReferenceConfigByAPI returns ReferenceConfig with given @opts
func NewReferenceConfigByAPI(opts ...ReferenceConfigOpt) *ReferenceConfig {
- newreferenceConfig := NewDefaultReferenceConfig()
+ newReferenceConfig := NewDefaultReferenceConfig()
for _, v := range opts {
- v(newreferenceConfig)
+ v(newReferenceConfig)
}
- return newreferenceConfig
+ return newReferenceConfig
}
// WithReferenceRegistry returns ReferenceConfigOpt with given registryKey: @registry
@@ -349,8 +348,8 @@ func NewProviderConfig(opts ...ProviderConfigOpt) *ProviderConfig {
return newConfig
}
-// WithPrividerRegistryConfig returns ProviderConfigOpt with given registry config: @regConfig
-func WithPrividerRegistryConfig(regConfig *RegistryConfig) ProviderConfigOpt {
+// WithProviderRegistryConfig returns ProviderConfigOpt with given registry config: @regConfig
+func WithProviderRegistryConfig(regConfig *RegistryConfig) ProviderConfigOpt {
return func(config *ProviderConfig) *ProviderConfig {
config.Registries[regConfig.Protocol] = regConfig
return config
@@ -398,7 +397,7 @@ type ServiceConfigOpt func(config *ServiceConfig) *ServiceConfig
// NewDefaultServiceConfig returns default ServiceConfig
func NewDefaultServiceConfig() *ServiceConfig {
- newServiceConfig := NewServiceConfig("", context.Background())
+ newServiceConfig := NewServiceConfig("")
newServiceConfig.Params = make(map[string]string)
newServiceConfig.Methods = make([]*MethodConfig, 0, 8)
return newServiceConfig
@@ -498,7 +497,7 @@ func NewDefaultApplicationConfig() *ApplicationConfig {
}
// NewApplicationConfig is named as api, because there is NewServiceConfig func already declared
-// NewApplicationConfig returns ApplicationConfig wigh default application config
+// NewApplicationConfig returns ApplicationConfig with default application config
func NewApplicationConfig(opts ...ApplicationConfigOpt) *ApplicationConfig {
defaultServiceConfig := NewDefaultApplicationConfig()
for _, v := range opts {
@@ -547,7 +546,7 @@ func WithAppVersion(version string) ApplicationConfigOpt {
}
}
-// WithAppEnvironment returns ApplicationConfigOpt wigh given environment @env
+// WithAppEnvironment returns ApplicationConfigOpt with given environment @env
func WithAppEnvironment(env string) ApplicationConfigOpt {
return func(config *ApplicationConfig) *ApplicationConfig {
config.Environment = env
diff --git a/config/config_center_config.go b/config/config_center_config.go
index 9573ee7..415eadc 100644
--- a/config/config_center_config.go
+++ b/config/config_center_config.go
@@ -44,7 +44,6 @@ import (
//
// ConfigCenter has currently supported Zookeeper, Nacos, Etcd, Consul, Apollo
type ConfigCenterConfig struct {
- // context context.Context
Protocol string `required:"true" yaml:"protocol" json:"protocol,omitempty"`
Address string `yaml:"address" json:"address,omitempty"`
Cluster string `yaml:"cluster" json:"cluster,omitempty"`
@@ -58,7 +57,6 @@ type ConfigCenterConfig struct {
AppId string `default:"dubbo" yaml:"app_id" json:"app_id,omitempty"`
TimeoutStr string `yaml:"timeout" json:"timeout,omitempty"`
RemoteRef string `required:"false" yaml:"remote_ref" json:"remote_ref,omitempty"`
- // timeout time.Duration
}
// UnmarshalYAML unmarshals the ConfigCenterConfig by @unmarshal function
diff --git a/config/config_loader.go b/config/config_loader.go
index 54617ab..b8fa2a1 100644
--- a/config/config_loader.go
+++ b/config/config_loader.go
@@ -57,7 +57,7 @@ var (
maxWait = 3
confRouterFile string
confBaseFile string
- uniformVirturlServiceConfigPath string
+ uniformVirtualServiceConfigPath string
uniformDestRuleConfigPath string
)
@@ -73,7 +73,7 @@ func DefaultInit() []LoaderInitOption {
fs.StringVar(&confConFile, "conConf", os.Getenv(constant.CONF_CONSUMER_FILE_PATH), "default client config path")
fs.StringVar(&confProFile, "proConf", os.Getenv(constant.CONF_PROVIDER_FILE_PATH), "default server config path")
fs.StringVar(&confRouterFile, "rouConf", os.Getenv(constant.CONF_ROUTER_FILE_PATH), "default router config path")
- fs.StringVar(&uniformVirturlServiceConfigPath, "vsConf", os.Getenv(constant.CONF_VIRTUAL_SERVICE_FILE_PATH), "default virtual service of uniform router config path")
+ fs.StringVar(&uniformVirtualServiceConfigPath, "vsConf", os.Getenv(constant.CONF_VIRTUAL_SERVICE_FILE_PATH), "default virtual service of uniform router config path")
fs.StringVar(&uniformDestRuleConfigPath, "drConf", os.Getenv(constant.CONF_DEST_RULE_FILE_PATH), "default destination rule of uniform router config path")
fs.Parse(os.Args[1:])
for len(fs.Args()) != 0 {
@@ -359,8 +359,8 @@ func selectMetadataServiceExportedURL() *common.URL {
}
func initRouter() {
- if uniformDestRuleConfigPath != "" && uniformVirturlServiceConfigPath != "" {
- if err := RouterInit(uniformVirturlServiceConfigPath, uniformDestRuleConfigPath); err != nil {
+ if uniformDestRuleConfigPath != "" && uniformVirtualServiceConfigPath != "" {
+ if err := RouterInit(uniformVirtualServiceConfigPath, uniformDestRuleConfigPath); err != nil {
logger.Warnf("[routerConfig init] %#v", err)
}
}
diff --git a/config/config_loader_options.go b/config/config_loader_options.go
index 488fafd..5133dcf 100644
--- a/config/config_loader_options.go
+++ b/config/config_loader_options.go
@@ -18,9 +18,12 @@
package config
import (
+ "log"
+)
+
+import (
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/common/logger"
- "log"
)
type LoaderInitOption interface {
diff --git a/config/config_loader_test.go b/config/config_loader_test.go
index 2fbe6ec..b0935a2 100644
--- a/config/config_loader_test.go
+++ b/config/config_loader_test.go
@@ -445,30 +445,30 @@ func (m *mockMetadataService) Version() (string, error) {
panic("implement me")
}
-func (mts *mockMetadataService) addURL(targetMap *sync.Map, url *common.URL) bool {
+func (m *mockMetadataService) addURL(targetMap *sync.Map, url *common.URL) bool {
var (
urlSet interface{}
loaded bool
)
logger.Debug(url.ServiceKey())
if urlSet, loaded = targetMap.LoadOrStore(url.ServiceKey(), skip.New(uint64(0))); loaded {
- mts.lock.RLock()
+ m.lock.RLock()
wantedUrl := urlSet.(*skip.SkipList).Get(url)
if len(wantedUrl) > 0 && wantedUrl[0] != nil {
- mts.lock.RUnlock()
+ m.lock.RUnlock()
return false
}
- mts.lock.RUnlock()
+ m.lock.RUnlock()
}
- mts.lock.Lock()
+ m.lock.Lock()
// double chk
wantedUrl := urlSet.(*skip.SkipList).Get(url)
if len(wantedUrl) > 0 && wantedUrl[0] != nil {
- mts.lock.Unlock()
+ m.lock.Unlock()
return false
}
urlSet.(*skip.SkipList).Insert(url)
- mts.lock.Unlock()
+ m.lock.Unlock()
return true
}
@@ -519,7 +519,7 @@ func (mr *mockServiceDiscoveryRegistry) UnSubscribe(*common.URL, registry.Notify
panic("implement me")
}
-func (s *mockServiceDiscoveryRegistry) GetServiceDiscovery() registry.ServiceDiscovery {
+func (mr *mockServiceDiscoveryRegistry) GetServiceDiscovery() registry.ServiceDiscovery {
return &mockServiceDiscovery{}
}
diff --git a/config/consumer_config.go b/config/consumer_config.go
index 59212a1..48586d0 100644
--- a/config/consumer_config.go
+++ b/config/consumer_config.go
@@ -37,10 +37,6 @@ const (
MaxWheelTimeSpan = 900e9 // 900s, 15 minute
)
-/////////////////////////
-// consumerConfig
-/////////////////////////
-
// ConsumerConfig is Consumer default configuration
type ConsumerConfig struct {
BaseConfig `yaml:",inline"`
diff --git a/config/graceful_shutdown_test.go b/config/graceful_shutdown_test.go
index aee9533..870302d 100644
--- a/config/graceful_shutdown_test.go
+++ b/config/graceful_shutdown_test.go
@@ -43,7 +43,6 @@ func TestBeforeShutdown(t *testing.T) {
return &mockRegistryProtocol{}
})
- // protocolConfigs := make(map[interface{}]interface{}, 16)
consumerReferences := map[string]*ReferenceConfig{}
consumerReferences[constant.DUBBO] = &ReferenceConfig{
Protocol: constant.DUBBO,
diff --git a/config/metadata_report_config_test.go b/config/metadata_report_config_test.go
index 1c585ee..46b7f83 100644
--- a/config/metadata_report_config_test.go
+++ b/config/metadata_report_config_test.go
@@ -17,7 +17,9 @@
package config
-import "testing"
+import (
+ "testing"
+)
import (
"github.com/stretchr/testify/assert"
@@ -37,8 +39,8 @@ func TestMetadataReportConfig_ToUrl(t *testing.T) {
"k": "v",
},
}
- url, error := metadataReportConfig.ToUrl()
- assert.NoError(t, error)
+ url, err := metadataReportConfig.ToUrl()
+ assert.NoError(t, err)
assert.Equal(t, "mock", url.Protocol)
assert.Equal(t, "127.0.0.1:2181", url.Location)
assert.Equal(t, "127.0.0.1", url.Ip)
diff --git a/config/provider_config.go b/config/provider_config.go
index dd5b492..61cb368 100644
--- a/config/provider_config.go
+++ b/config/provider_config.go
@@ -31,10 +31,6 @@ import (
"dubbo.apache.org/dubbo-go/v3/common/yaml"
)
-/////////////////////////
-// providerConfig
-/////////////////////////
-
// ProviderConfig is the default configuration of service provider
type ProviderConfig struct {
BaseConfig `yaml:",inline"`
diff --git a/config/reference_config.go b/config/reference_config.go
index f4d43cb..32d5de1 100644
--- a/config/reference_config.go
+++ b/config/reference_config.go
@@ -18,7 +18,6 @@
package config
import (
- "context"
"fmt"
"net/url"
"strconv"
@@ -42,7 +41,6 @@ import (
// ReferenceConfig is the configuration of service consumer
type ReferenceConfig struct {
- context context.Context
pxy *proxy.Proxy
id string
InterfaceName string `required:"true" yaml:"interface" json:"interface,omitempty" property:"interface"`
@@ -75,8 +73,8 @@ func (c *ReferenceConfig) Prefix() string {
}
// NewReferenceConfig The only way to get a new ReferenceConfig
-func NewReferenceConfig(id string, ctx context.Context) *ReferenceConfig {
- return &ReferenceConfig{id: id, context: ctx}
+func NewReferenceConfig(id string) *ReferenceConfig {
+ return &ReferenceConfig{id: id}
}
// UnmarshalYAML unmarshals the ReferenceConfig by @unmarshal function
diff --git a/config/registry_config.go b/config/registry_config.go
index 26683df..92d92a6 100644
--- a/config/registry_config.go
+++ b/config/registry_config.go
@@ -35,8 +35,7 @@ import (
// RegistryConfig is the configuration of the registry center
type RegistryConfig struct {
- Protocol string `required:"true" yaml:"protocol" json:"protocol,omitempty" property:"protocol"`
- // I changed "type" to "protocol" ,the same as "protocol" field in java class RegistryConfig
+ Protocol string `required:"true" yaml:"protocol" json:"protocol,omitempty" property:"protocol"`
TimeoutStr string `yaml:"timeout" default:"5s" json:"timeout,omitempty" property:"timeout"` // unit: second
Group string `yaml:"group" json:"group,omitempty" property:"group"`
TTL string `yaml:"ttl" default:"10m" json:"ttl,omitempty" property:"ttl"` // unit: minute
@@ -49,8 +48,6 @@ type RegistryConfig struct {
Preferred bool `yaml:"preferred" json:"preferred,omitempty" property:"preferred"`
// The region where the registry belongs, usually used to isolate traffics
Zone string `yaml:"zone" json:"zone,omitempty" property:"zone"`
- //// Force must user the region, property zone is specified.
- //ZoneForce bool `yaml:"zoneForce" json:"zoneForce,omitempty" property:"zoneForce"`
// Affects traffic distribution among registries,
// useful when subscribe to multiple registries Take effect only when no preferred registry is specified.
Weight int64 `yaml:"weight" json:"weight,omitempty" property:"weight"`
@@ -129,7 +126,6 @@ func (c *RegistryConfig) getUrlMap(roleType common.RoleType) url.Values {
urlMap.Set(constant.REGISTRY_KEY+"."+constant.REGISTRY_LABEL_KEY, strconv.FormatBool(true))
urlMap.Set(constant.REGISTRY_KEY+"."+constant.PREFERRED_KEY, strconv.FormatBool(c.Preferred))
urlMap.Set(constant.REGISTRY_KEY+"."+constant.ZONE_KEY, c.Zone)
- // urlMap.Set(constant.REGISTRY_KEY+"."+constant.ZONE_FORCE_KEY, strconv.FormatBool(c.ZoneForce))
urlMap.Set(constant.REGISTRY_KEY+"."+constant.WEIGHT_KEY, strconv.FormatInt(c.Weight, 10))
urlMap.Set(constant.REGISTRY_TTL_KEY, c.TTL)
for k, v := range c.Params {
diff --git a/config/service_config.go b/config/service_config.go
index fb84c35..653a297 100644
--- a/config/service_config.go
+++ b/config/service_config.go
@@ -19,7 +19,6 @@ package config
import (
"container/list"
- "context"
"fmt"
"net/url"
"strconv"
@@ -46,7 +45,6 @@ import (
// ServiceConfig is the configuration of the service provider
type ServiceConfig struct {
- context context.Context
id string
Filter string `yaml:"filter" json:"filter,omitempty" property:"filter"`
Protocol string `default:"dubbo" required:"true" yaml:"protocol" json:"protocol,omitempty" property:"protocol"` // multi protocol support, split by ','
@@ -108,9 +106,8 @@ func (c *ServiceConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
}
// NewServiceConfig The only way to get a new ServiceConfig
-func NewServiceConfig(id string, context context.Context) *ServiceConfig {
+func NewServiceConfig(id string) *ServiceConfig {
return &ServiceConfig{
- context: context,
id: id,
unexported: atomic.NewBool(false),
exported: atomic.NewBool(false),
diff --git a/config/service_config_test.go b/config/service_config_test.go
index f37167c..4c64c70 100644
--- a/config/service_config_test.go
+++ b/config/service_config_test.go
@@ -19,8 +19,6 @@ package config
import (
"testing"
-
- "dubbo.apache.org/dubbo-go/v3/common"
)
import (
@@ -29,6 +27,7 @@ import (
)
import (
+ "dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/extension"
)
diff --git a/metadata/service/exporter/configurable/exporter.go b/metadata/service/exporter/configurable/exporter.go
index d26803e..f3f2858 100644
--- a/metadata/service/exporter/configurable/exporter.go
+++ b/metadata/service/exporter/configurable/exporter.go
@@ -18,7 +18,6 @@
package configurable
import (
- "context"
"errors"
"sync"
)
@@ -49,7 +48,7 @@ func NewMetadataServiceExporter(metadataService service.MetadataService) exporte
// Export will export the metadataService
func (exporter *MetadataServiceExporter) Export(url *common.URL) error {
if !exporter.IsExported() {
- serviceConfig := config.NewServiceConfig(constant.SIMPLE_METADATA_SERVICE_NAME, context.Background())
+ serviceConfig := config.NewServiceConfig(constant.SIMPLE_METADATA_SERVICE_NAME)
serviceConfig.Protocol = constant.DEFAULT_PROTOCOL
if url == nil || url.SubURL == nil {
return errors.New("metadata server url is nil, pls check your configuration")