Skip to content

Commit

Permalink
replace default config string with const value
Browse files Browse the repository at this point in the history
  • Loading branch information
dongjianhui committed Apr 29, 2021
1 parent c1e2643 commit d912b22
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
11 changes: 11 additions & 0 deletions common/constant/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,14 @@ const (
DEFAULT_LOG_CONF_FILE_PATH = "../profiles/dev/log.yml"
DEFAULT_ROUTER_CONF_FILE_PATH = "../profiles/dev/router.yml"
)

// default config value
const (
DEFAULT_REGISTRY_ZK_ID = "demoZK"
DEFAULT_REGISTRY_ZK_PROTOCOL = "zookeeper"
DEFAULT_REGISTRY_ZK_TIMEOUT = "3s"
DEFAULT_REGISTRY_ZK_ADDRESS = "127.0.0.1:2181"

DEFAULT_PROTOCOL_DUBBO_NAME = "dubbo"
DEFAULT_PROTOCOL_DUBBO_PORT = "20000"
)
16 changes: 8 additions & 8 deletions config/config_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,20 @@ func DefaultInit() []LoaderInitOption {
// setDefaultValue set default value for providerConfig or consumerConfig if it is null
func setDefaultValue(target interface{}) {
registryConfig := &RegistryConfig{
Protocol: "zookeeper",
TimeoutStr: "3s",
Address: "127.0.0.1:2181",
Protocol: constant.DEFAULT_REGISTRY_ZK_PROTOCOL,
TimeoutStr: constant.DEFAULT_REGISTRY_ZK_TIMEOUT,
Address: constant.DEFAULT_REGISTRY_ZK_ADDRESS,
}
switch target.(type) {
case *ProviderConfig:
p := target.(*ProviderConfig)
if len(p.Registries) == 0 {
p.Registries["demoZK"] = registryConfig
p.Registries[constant.DEFAULT_REGISTRY_ZK_ID] = registryConfig
}
if len(p.Protocols) == 0 {
p.Protocols["dubbo"] = &ProtocolConfig{
Name: "dubbo",
Port: "20000",
p.Protocols[constant.DEFAULT_PROTOCOL] = &ProtocolConfig{
Name: constant.DEFAULT_PROTOCOL_DUBBO_NAME,
Port: constant.DEFAULT_PROTOCOL_DUBBO_PORT,
}
}
if p.ApplicationConfig == nil {
Expand All @@ -118,7 +118,7 @@ func setDefaultValue(target interface{}) {
default:
c := target.(*ConsumerConfig)
if len(c.Registries) == 0 {
c.Registries["demoZK"] = registryConfig
c.Registries[constant.DEFAULT_REGISTRY_ZK_ID] = registryConfig
}
if c.ApplicationConfig == nil {
c.ApplicationConfig = NewDefaultApplicationConfig()
Expand Down

0 comments on commit d912b22

Please sign in to comment.