Skip to content

Commit

Permalink
replace default config string with const value (#1182)
Browse files Browse the repository at this point in the history
* replace default config string with const value

* delete some duplicate keys

Co-authored-by: dongjianhui <dongjianhui@yuanfudao.com>
  • Loading branch information
Mulavar and dongjianhui committed Apr 29, 2021
1 parent c1e2643 commit ddc39a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
8 changes: 8 additions & 0 deletions common/constant/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,11 @@ 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_KEY
DEFAULT_REGISTRY_ZK_TIMEOUT = "3s"
DEFAULT_REGISTRY_ZK_ADDRESS = "127.0.0.1:2181"
)
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,
Port: string(constant.DEFAULT_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 ddc39a3

Please sign in to comment.