Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace default config string with const value #1182

Merged
merged 2 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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