Skip to content

Commit

Permalink
use common.URL as parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
beiwei30 committed Dec 22, 2020
1 parent 8789da2 commit 95432d1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
8 changes: 5 additions & 3 deletions config/interfaces/config_post_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@

package interfaces

import "net/url"
import (
"github.com/apache/dubbo-go/common"
)

// ConfigPostProcessor is an extension to give users a chance to customize configs against ReferenceConfig and
// ServiceConfig during deployment time.
type ConfigPostProcessor interface {
// PostProcessReferenceConfig customizes ReferenceConfig's params.
PostProcessReferenceConfig(url.Values)
PostProcessReferenceConfig(*common.URL)

// PostProcessServiceConfig customizes ServiceConfig's params.
PostProcessServiceConfig(url.Values)
PostProcessServiceConfig(*common.URL)
}
11 changes: 5 additions & 6 deletions config/reference_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,18 @@ func (c *ReferenceConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

// Refer ...
func (c *ReferenceConfig) Refer(_ interface{}) {
urlMap := c.getUrlMap()
c.postProcessConfig(urlMap)

cfgURL := common.NewURLWithOptions(
common.WithPath(c.InterfaceName),
common.WithProtocol(c.Protocol),
common.WithParams(urlMap),
common.WithParams(c.getUrlMap()),
common.WithParamsValue(constant.BEAN_NAME_KEY, c.id),
)
if c.ForceTag {
cfgURL.AddParam(constant.ForceUseTag, "true")
}

c.postProcessConfig(cfgURL)

if c.Url != "" {
// 1. user specified URL, could be peer-to-peer address, or register center's address.
urlStrings := gxstrings.RegSplit(c.Url, "\\s*[;]+\\s*")
Expand Down Expand Up @@ -254,8 +253,8 @@ func (c *ReferenceConfig) GenericLoad(id string) {
}

// postProcessConfig asks registered ConfigPostProcessor to post-process the current ReferenceConfig.
func (c *ReferenceConfig) postProcessConfig(values url.Values) {
func (c *ReferenceConfig) postProcessConfig(url *common.URL) {
for _, p := range extension.GetConfigPostProcessors() {
p.PostProcessReferenceConfig(values)
p.PostProcessReferenceConfig(url)
}
}
9 changes: 4 additions & 5 deletions config/service_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,7 @@ func (c *ServiceConfig) Export() error {
}

regUrls := loadRegistries(c.Registry, providerConfig.Registries, common.PROVIDER)

urlMap := c.getUrlMap()
c.postProcessConfig(urlMap)

protocolConfigs := loadProtocol(c.Protocol, c.Protocols)
if len(protocolConfigs) == 0 {
logger.Warnf("The service %v's '%v' protocols don't has right protocolConfigs", c.InterfaceName, c.Protocol)
Expand Down Expand Up @@ -201,6 +198,8 @@ func (c *ServiceConfig) Export() error {
ivkURL.AddParam(constant.Tagkey, c.Tag)
}

c.postProcessConfig(ivkURL)

if len(regUrls) > 0 {
c.cacheMutex.Lock()
if c.cacheProtocol == nil {
Expand Down Expand Up @@ -337,8 +336,8 @@ func (c *ServiceConfig) GetExportedUrls() []*common.URL {
}

// postProcessConfig asks registered ConfigPostProcessor to post-process the current ServiceConfig.
func (c *ServiceConfig) postProcessConfig(values url.Values) {
func (c *ServiceConfig) postProcessConfig(url *common.URL) {
for _, p := range extension.GetConfigPostProcessors() {
p.PostProcessServiceConfig(values)
p.PostProcessServiceConfig(url)
}
}

0 comments on commit 95432d1

Please sign in to comment.