diff --git a/config/protocol_config.go b/config/protocol_config.go index 586b53165c5cdd1684dc810f07061d31eef1944f..33de976bc6f5bf7341ddcff8d51c505cf23bbccd 100644 --- a/config/protocol_config.go +++ b/config/protocol_config.go @@ -38,14 +38,13 @@ func (c *ProtocolConfig) Prefix() string { } func loadProtocol(protocolsIds string, protocols map[string]*ProtocolConfig) []*ProtocolConfig { - var returnProtocols []*ProtocolConfig + returnProtocols := make([]*ProtocolConfig, 0, len(protocols)) for _, v := range strings.Split(protocolsIds, ",") { for k, protocol := range protocols { if v == k { returnProtocols = append(returnProtocols, protocol) } } - } return returnProtocols } diff --git a/config/reference_config.go b/config/reference_config.go index e8e68a0b10a43c988088eac9290fff5eddaabf40..bd5fc66f6632ceede8f6574860f67d7005e29805 100644 --- a/config/reference_config.go +++ b/config/reference_config.go @@ -101,7 +101,7 @@ func (c *ReferenceConfig) Refer(_ interface{}) { ) if c.Url != "" { - //1. user specified URL, could be peer-to-peer address, or register center's address. + // 1. user specified URL, could be peer-to-peer address, or register center's address. urlStrings := gxstrings.RegSplit(c.Url, "\\s*[;]+\\s*") for _, urlStr := range urlStrings { serviceUrl, err := common.NewURL(urlStr) @@ -121,10 +121,10 @@ func (c *ReferenceConfig) Refer(_ interface{}) { } } } else { - //2. assemble SubURL from register center's configuration妯″紡 + // 2. assemble SubURL from register center's configuration妯″紡 c.urls = loadRegistries(c.Registry, consumerConfig.Registries, common.CONSUMER) - //set url to regUrls + // set url to regUrls for _, regUrl := range c.urls { regUrl.SubURL = cfgURL } @@ -133,7 +133,7 @@ func (c *ReferenceConfig) Refer(_ interface{}) { if len(c.urls) == 1 { c.invoker = extension.GetProtocol(c.urls[0].Protocol).Refer(*c.urls[0]) } else { - var invokers []protocol.Invoker + invokers := make([]protocol.Invoker, 0, len(c.urls)) var regUrl *common.URL for _, u := range c.urls { invokers = append(invokers, extension.GetProtocol(u.Protocol).Refer(*u)) @@ -150,7 +150,7 @@ func (c *ReferenceConfig) Refer(_ interface{}) { } } - //create proxy + // create proxy if c.Async { callback := GetCallback(c.id) c.pxy = extension.GetProxyFactory(consumerConfig.ProxyFactory).GetAsyncProxy(c.invoker, callback, cfgURL)