Skip to content

Commit

Permalink
fix type; remove useless code (#1243)
Browse files Browse the repository at this point in the history
* fix type; remove useless code

* log
  • Loading branch information
gaoxinge authored Jun 7, 2021
1 parent 97a0cac commit 7ef3eff
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 60 deletions.
3 changes: 1 addition & 2 deletions common/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package logger
import (
"flag"
"io/ioutil"
"log"
"os"
"path"
)
Expand Down Expand Up @@ -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)
}
}

Expand Down
3 changes: 0 additions & 3 deletions config/base_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -244,7 +242,6 @@ func setFieldValue(val reflect.Value, id reflect.Value, config *config.InmemoryC
}
}
setBaseValue(f)

}
}
}
Expand Down
1 change: 0 additions & 1 deletion config/base_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 9 additions & 10 deletions config/config_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package config

import (
"context"
"time"
)

Expand Down Expand Up @@ -259,19 +258,19 @@ 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
}

// 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions config/config_center_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions config/config_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var (
maxWait = 3
confRouterFile string
confBaseFile string
uniformVirturlServiceConfigPath string
uniformVirtualServiceConfigPath string
uniformDestRuleConfigPath string
)

Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Expand Down
5 changes: 4 additions & 1 deletion config/config_loader_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

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 {
Expand Down
16 changes: 8 additions & 8 deletions config/config_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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{}
}

Expand Down
4 changes: 0 additions & 4 deletions config/consumer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ const (
MaxWheelTimeSpan = 900e9 // 900s, 15 minute
)

/////////////////////////
// consumerConfig
/////////////////////////

// ConsumerConfig is Consumer default configuration
type ConsumerConfig struct {
BaseConfig `yaml:",inline"`
Expand Down
1 change: 0 additions & 1 deletion config/graceful_shutdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions config/metadata_report_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package config

import "testing"
import (
"testing"
)

import (
"github.com/stretchr/testify/assert"
Expand All @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions config/provider_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
6 changes: 2 additions & 4 deletions config/reference_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package config

import (
"context"
"fmt"
"net/url"
"strconv"
Expand All @@ -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"`
Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions config/registry_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions config/service_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package config

import (
"container/list"
"context"
"fmt"
"net/url"
"strconv"
Expand All @@ -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 ','
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions config/service_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package config

import (
"testing"

"dubbo.apache.org/dubbo-go/v3/common"
)

import (
Expand All @@ -29,6 +27,7 @@ import (
)

import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/extension"
)

Expand Down
3 changes: 1 addition & 2 deletions metadata/service/exporter/configurable/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package configurable

import (
"context"
"errors"
"sync"
)
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 7ef3eff

Please sign in to comment.