You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2020/08/04 01:37:47 UTC
[GitHub] [dubbo-go] flycash commented on a change in pull request #687: Rft: Optimize remotes configuration
flycash commented on a change in pull request #687:
URL: https://github.com/apache/dubbo-go/pull/687#discussion_r464748857
##########
File path: config/base_config.go
##########
@@ -72,72 +69,19 @@ func (c *BaseConfig) GetRemoteConfig(name string) (config *RemoteConfig, ok bool
return
}
-// startConfigCenter will start the config center.
-// it will prepare the environment
-func (c *BaseConfig) startConfigCenter() error {
- url, err := common.NewURL(c.ConfigCenterConfig.Address,
- common.WithProtocol(c.ConfigCenterConfig.Protocol), common.WithParams(c.ConfigCenterConfig.GetUrlMap()))
- if err != nil {
- return err
- }
- c.configCenterUrl = &url
- if c.prepareEnvironment() != nil {
- return perrors.WithMessagef(err, "start config center error!")
- }
- // c.fresh()
- return err
-}
-
-func (c *BaseConfig) prepareEnvironment() error {
- factory := extension.GetConfigCenterFactory(c.ConfigCenterConfig.Protocol)
- dynamicConfig, err := factory.GetDynamicConfiguration(c.configCenterUrl)
- config.GetEnvInstance().SetDynamicConfiguration(dynamicConfig)
- if err != nil {
- logger.Errorf("Get dynamic configuration error , error message is %v", err)
- return perrors.WithStack(err)
- }
- content, err := dynamicConfig.GetProperties(c.ConfigCenterConfig.ConfigFile, config_center.WithGroup(c.ConfigCenterConfig.Group))
- if err != nil {
- logger.Errorf("Get config content in dynamic configuration error , error message is %v", err)
- return perrors.WithStack(err)
- }
- var appGroup string
- var appContent string
- if providerConfig != nil && providerConfig.ApplicationConfig != nil &&
- reflect.ValueOf(c.fatherConfig).Elem().Type().Name() == "ProviderConfig" {
- appGroup = providerConfig.ApplicationConfig.Name
- } else if consumerConfig != nil && consumerConfig.ApplicationConfig != nil &&
- reflect.ValueOf(c.fatherConfig).Elem().Type().Name() == "ConsumerConfig" {
- appGroup = consumerConfig.ApplicationConfig.Name
- }
+func (c *BaseConfig) toURL(name string, protocol string) (common.URL, error) {
+ rc, ok := GetBaseConfig().GetRemoteConfig(name)
- if len(appGroup) != 0 {
- configFile := c.ConfigCenterConfig.AppConfigFile
- if len(configFile) == 0 {
- configFile = c.ConfigCenterConfig.ConfigFile
- }
- appContent, err = dynamicConfig.GetProperties(configFile, config_center.WithGroup(appGroup))
- if err != nil {
- return perrors.WithStack(err)
- }
+ if !ok {
+ return common.URL{}, perrors.New("Could not find out the remote ref config, name: " + name)
}
- // global config file
- mapContent, err := dynamicConfig.Parser().Parse(content)
- if err != nil {
- return perrors.WithStack(err)
- }
- config.GetEnvInstance().UpdateExternalConfigMap(mapContent)
- // appGroup config file
- if len(appContent) != 0 {
- appMapConent, err := dynamicConfig.Parser().Parse(appContent)
- if err != nil {
- return perrors.WithStack(err)
- }
- config.GetEnvInstance().UpdateAppExternalConfigMap(appMapConent)
- }
-
- return nil
+ return common.NewURL(rc.Address,
Review comment:
I prefer to define method inside RemoteRef:
```go
func (rc *RemoteRef) ToUrl() {
}
```
The RemoteRef is used in many modules, in this way we make sure that if we add more fileds to RemoteRef, all users is updated.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org