diff --git a/cluster/cluster_impl/base_cluster_invoker.go b/cluster/cluster_impl/base_cluster_invoker.go
index 52e2156885a2e6cc3c35da75a1d0db8bcfcabec0..d93e9a6a98a8cbf7ee2cb97abd0248353e0c3154 100644
--- a/cluster/cluster_impl/base_cluster_invoker.go
+++ b/cluster/cluster_impl/base_cluster_invoker.go
@@ -18,6 +18,7 @@
package cluster_impl
import (
+ gxnet "github.com/dubbogo/gost/net"
perrors "github.com/pkg/errors"
"go.uber.org/atomic"
)
@@ -27,7 +28,6 @@ import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
- "github.com/apache/dubbo-go/common/utils"
"github.com/apache/dubbo-go/protocol"
)
@@ -63,7 +63,7 @@ func (invoker *baseClusterInvoker) IsAvailable() bool {
//check invokers availables
func (invoker *baseClusterInvoker) checkInvokers(invokers []protocol.Invoker, invocation protocol.Invocation) error {
if len(invokers) == 0 {
- ip, _ := utils.GetLocalIP()
+ ip, _ := gxnet.GetLocalIP()
return perrors.Errorf("Failed to invoke the method %v. No provider available for the service %v from "+
"registry %v on the consumer %v using the dubbo version %v .Please check if the providers have been started and registered.",
invocation.MethodName(), invoker.directory.GetUrl().SubURL.Key(), invoker.directory.GetUrl().String(), ip, constant.Version)
@@ -75,7 +75,7 @@ func (invoker *baseClusterInvoker) checkInvokers(invokers []protocol.Invoker, in
//check cluster invoker is destroyed or not
func (invoker *baseClusterInvoker) checkWhetherDestroyed() error {
if invoker.destroyed.Load() {
- ip, _ := utils.GetLocalIP()
+ ip, _ := gxnet.GetLocalIP()
return perrors.Errorf("Rpc cluster invoker for %v on consumer %v use dubbo version %v is now destroyed! can not invoke any more. ",
invoker.directory.GetUrl().Service(), ip, constant.Version)
}
diff --git a/cluster/cluster_impl/failover_cluster_invoker.go b/cluster/cluster_impl/failover_cluster_invoker.go
index 70db6d4c1cdf5150d607d6c5250dfb3da631e95a..dcce7369931a11f31fb6b9e4e1a6c0aa0ec7cdf6 100644
--- a/cluster/cluster_impl/failover_cluster_invoker.go
+++ b/cluster/cluster_impl/failover_cluster_invoker.go
@@ -22,6 +22,7 @@ import (
)
import (
+ gxnet "github.com/dubbogo/gost/net"
perrors "github.com/pkg/errors"
)
@@ -29,7 +30,6 @@ import (
"github.com/apache/dubbo-go/cluster"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/logger"
- "github.com/apache/dubbo-go/common/utils"
"github.com/apache/dubbo-go/protocol"
)
@@ -72,6 +72,9 @@ func (invoker *failoverClusterInvoker) Invoke(invocation protocol.Invocation) pr
invoked := []protocol.Invoker{}
providers := []string{}
var result protocol.Result
+ if retries > len(invokers) {
+ retries = len(invokers)
+ }
for i := 0; i <= retries; i++ {
//Reselect before retry to avoid a change of candidate `invokers`.
//NOTE: if `invokers` changed, then `invoked` also lose accuracy.
@@ -87,6 +90,9 @@ func (invoker *failoverClusterInvoker) Invoke(invocation protocol.Invocation) pr
}
}
ivk := invoker.doSelect(loadbalance, invocation, invokers, invoked)
+ if ivk == nil {
+ continue
+ }
invoked = append(invoked, ivk)
//DO INVOKE
result = ivk.Invoke(invocation)
@@ -97,7 +103,7 @@ func (invoker *failoverClusterInvoker) Invoke(invocation protocol.Invocation) pr
return result
}
}
- ip, _ := utils.GetLocalIP()
+ ip, _ := gxnet.GetLocalIP()
return &protocol.RPCResult{Err: perrors.Errorf("Failed to invoke the method %v in the service %v. Tried %v times of "+
"the providers %v (%v/%v)from the registry %v on the consumer %v using the dubbo version %v. Last error is %v.",
methodName, invoker.GetUrl().Service(), retries, providers, len(providers), len(invokers), invoker.directory.GetUrl(), ip, constant.Version, result.Error().Error(),
diff --git a/cluster/router/condition_router.go b/cluster/router/condition_router.go
index b9632e29119691009bf59fb7cc5af24ea33dd120..a196ceb5771422f06a820986a02499f9fe3523dc 100644
--- a/cluster/router/condition_router.go
+++ b/cluster/router/condition_router.go
@@ -24,7 +24,8 @@ import (
)
import (
- "github.com/dubbogo/gost/container"
+ "github.com/dubbogo/gost/container/gxset"
+ gxnet "github.com/dubbogo/gost/net"
perrors "github.com/pkg/errors"
)
@@ -32,7 +33,6 @@ import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/logger"
- "github.com/apache/dubbo-go/common/utils"
"github.com/apache/dubbo-go/protocol"
)
@@ -126,7 +126,7 @@ func (c *ConditionRouter) Route(invokers []protocol.Invoker, url common.URL, inv
if len(c.ThenCondition) == 0 {
return result
}
- localIP, _ := utils.GetLocalIP()
+ localIP, _ := gxnet.GetLocalIP()
for _, invoker := range invokers {
isMatchThen, err := c.MatchThen(invoker.GetUrl(), url)
if err != nil {
@@ -157,7 +157,7 @@ func parseRule(rule string) (map[string]MatchPair, error) {
return condition, nil
}
var pair MatchPair
- values := container.NewSet()
+ values := gxset.NewSet()
reg := regexp.MustCompile(`([&!=,]*)\s*([^&!=,\s]+)`)
var startIndex = 0
if indexTuple := reg.FindIndex([]byte(rule)); len(indexTuple) > 0 {
@@ -170,8 +170,8 @@ func parseRule(rule string) (map[string]MatchPair, error) {
switch separator {
case "":
pair = MatchPair{
- Matches: container.NewSet(),
- Mismatches: container.NewSet(),
+ Matches: gxset.NewSet(),
+ Mismatches: gxset.NewSet(),
}
condition[content] = pair
case "&":
@@ -179,8 +179,8 @@ func parseRule(rule string) (map[string]MatchPair, error) {
pair = r
} else {
pair = MatchPair{
- Matches: container.NewSet(),
- Mismatches: container.NewSet(),
+ Matches: gxset.NewSet(),
+ Mismatches: gxset.NewSet(),
}
condition[content] = pair
}
@@ -257,8 +257,8 @@ func MatchCondition(pairs map[string]MatchPair, url *common.URL, param *common.U
}
type MatchPair struct {
- Matches *container.HashSet
- Mismatches *container.HashSet
+ Matches *gxset.HashSet
+ Mismatches *gxset.HashSet
}
func (pair MatchPair) isMatch(value string, param *common.URL) bool {
diff --git a/cluster/router/condition_router_test.go b/cluster/router/condition_router_test.go
index 577c5c416f87b8d56e88a540d43bf092784b0756..e7534f95959fc6737e1c52a950d0789bb431484d 100644
--- a/cluster/router/condition_router_test.go
+++ b/cluster/router/condition_router_test.go
@@ -26,6 +26,7 @@ import (
)
import (
+ "github.com/dubbogo/gost/net"
perrors "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
@@ -33,7 +34,6 @@ import (
import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/logger"
- "github.com/apache/dubbo-go/common/utils"
"github.com/apache/dubbo-go/protocol"
"github.com/apache/dubbo-go/protocol/invocation"
)
@@ -146,7 +146,7 @@ func TestRoute_matchWhen(t *testing.T) {
}
func TestRoute_matchFilter(t *testing.T) {
- localIP, _ := utils.GetLocalIP()
+ localIP, _ := gxnet.GetLocalIP()
url1, _ := common.NewURL(context.TODO(), "dubbo://10.20.3.3:20880/com.foo.BarService?default.serialization=fastjson")
url2, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
@@ -204,7 +204,7 @@ func TestRoute_methodRoute(t *testing.T) {
func TestRoute_ReturnFalse(t *testing.T) {
url, _ := common.NewURL(context.TODO(), "")
- localIP, _ := utils.GetLocalIP()
+ localIP, _ := gxnet.GetLocalIP()
invokers := []protocol.Invoker{NewMockInvoker(url, 1), NewMockInvoker(url, 2), NewMockInvoker(url, 3)}
inv := &invocation.RPCInvocation{}
rule := base64.URLEncoding.EncodeToString([]byte("host = " + localIP + " => false"))
@@ -215,7 +215,7 @@ func TestRoute_ReturnFalse(t *testing.T) {
}
func TestRoute_ReturnEmpty(t *testing.T) {
- localIP, _ := utils.GetLocalIP()
+ localIP, _ := gxnet.GetLocalIP()
url, _ := common.NewURL(context.TODO(), "")
invokers := []protocol.Invoker{NewMockInvoker(url, 1), NewMockInvoker(url, 2), NewMockInvoker(url, 3)}
inv := &invocation.RPCInvocation{}
@@ -227,7 +227,7 @@ func TestRoute_ReturnEmpty(t *testing.T) {
}
func TestRoute_ReturnAll(t *testing.T) {
- localIP, _ := utils.GetLocalIP()
+ localIP, _ := gxnet.GetLocalIP()
invokers := []protocol.Invoker{&MockInvoker{}, &MockInvoker{}, &MockInvoker{}}
inv := &invocation.RPCInvocation{}
rule := base64.URLEncoding.EncodeToString([]byte("host = " + localIP + " => " + " host = " + localIP))
@@ -238,7 +238,7 @@ func TestRoute_ReturnAll(t *testing.T) {
}
func TestRoute_HostFilter(t *testing.T) {
- localIP, _ := utils.GetLocalIP()
+ localIP, _ := gxnet.GetLocalIP()
url1, _ := common.NewURL(context.TODO(), "dubbo://10.20.3.3:20880/com.foo.BarService")
url2, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
@@ -257,7 +257,7 @@ func TestRoute_HostFilter(t *testing.T) {
}
func TestRoute_Empty_HostFilter(t *testing.T) {
- localIP, _ := utils.GetLocalIP()
+ localIP, _ := gxnet.GetLocalIP()
url1, _ := common.NewURL(context.TODO(), "dubbo://10.20.3.3:20880/com.foo.BarService")
url2, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
@@ -276,7 +276,7 @@ func TestRoute_Empty_HostFilter(t *testing.T) {
}
func TestRoute_False_HostFilter(t *testing.T) {
- localIP, _ := utils.GetLocalIP()
+ localIP, _ := gxnet.GetLocalIP()
url1, _ := common.NewURL(context.TODO(), "dubbo://10.20.3.3:20880/com.foo.BarService")
url2, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
@@ -295,7 +295,7 @@ func TestRoute_False_HostFilter(t *testing.T) {
}
func TestRoute_Placeholder(t *testing.T) {
- localIP, _ := utils.GetLocalIP()
+ localIP, _ := gxnet.GetLocalIP()
url1, _ := common.NewURL(context.TODO(), "dubbo://10.20.3.3:20880/com.foo.BarService")
url2, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
@@ -314,7 +314,7 @@ func TestRoute_Placeholder(t *testing.T) {
}
func TestRoute_NoForce(t *testing.T) {
- localIP, _ := utils.GetLocalIP()
+ localIP, _ := gxnet.GetLocalIP()
url1, _ := common.NewURL(context.TODO(), "dubbo://10.20.3.3:20880/com.foo.BarService")
url2, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
@@ -331,7 +331,7 @@ func TestRoute_NoForce(t *testing.T) {
}
func TestRoute_Force(t *testing.T) {
- localIP, _ := utils.GetLocalIP()
+ localIP, _ := gxnet.GetLocalIP()
url1, _ := common.NewURL(context.TODO(), "dubbo://10.20.3.3:20880/com.foo.BarService")
url2, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
diff --git a/common/url.go b/common/url.go
index bf58ca188c1769b81ed475f06852d0f4229ab97d..6e7a843c8f4d2d3b24caf50983baf041e2dd036d 100644
--- a/common/url.go
+++ b/common/url.go
@@ -31,7 +31,7 @@ import (
)
import (
- "github.com/dubbogo/gost/container"
+ "github.com/dubbogo/gost/container/gxset"
"github.com/jinzhu/copier"
perrors "github.com/pkg/errors"
"github.com/satori/go.uuid"
@@ -447,7 +447,7 @@ func (c URL) GetMethodParam(method string, key string, d string) string {
return r
}
-func (c *URL) RemoveParams(set *container.HashSet) {
+func (c *URL) RemoveParams(set *gxset.HashSet) {
c.paramsLock.Lock()
defer c.paramsLock.Unlock()
for k := range set.Items {
diff --git a/common/utils/net.go b/common/utils/net.go
deleted file mode 100644
index 47a250231756a63735eedef3f4990bb7e038e748..0000000000000000000000000000000000000000
--- a/common/utils/net.go
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package utils
-
-import (
- "net"
- "strings"
-)
-
-import (
- perrors "github.com/pkg/errors"
-)
-
-var (
- privateBlocks []*net.IPNet
-)
-
-func init() {
- for _, b := range []string{"10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"} {
- if _, block, err := net.ParseCIDR(b); err == nil {
- privateBlocks = append(privateBlocks, block)
- }
- }
-}
-
-func GetLocalIP() (string, error) {
- faces, err := net.Interfaces()
- if err != nil {
- return "", perrors.WithStack(err)
- }
-
- var addr net.IP
- for _, face := range faces {
- if !isValidNetworkInterface(face) {
- continue
- }
-
- addrs, err := face.Addrs()
- if err != nil {
- return "", perrors.WithStack(err)
- }
-
- if ipv4, ok := getValidIPv4(addrs); ok {
- addr = ipv4
- if isPrivateIP(ipv4) {
- return ipv4.String(), nil
- }
- }
- }
-
- if addr == nil {
- return "", perrors.Errorf("can not get local IP")
- }
-
- return addr.String(), nil
-}
-
-func isPrivateIP(ip net.IP) bool {
- for _, priv := range privateBlocks {
- if priv.Contains(ip) {
- return true
- }
- }
- return false
-}
-
-func getValidIPv4(addrs []net.Addr) (net.IP, bool) {
- for _, addr := range addrs {
- var ip net.IP
-
- switch v := addr.(type) {
- case *net.IPNet:
- ip = v.IP
- case *net.IPAddr:
- ip = v.IP
- }
-
- if ip == nil || ip.IsLoopback() {
- continue
- }
-
- ip = ip.To4()
- if ip == nil {
- // not an valid ipv4 address
- continue
- }
-
- return ip, true
- }
- return nil, false
-}
-
-func isValidNetworkInterface(face net.Interface) bool {
- if face.Flags&net.FlagUp == 0 {
- // interface down
- return false
- }
-
- if face.Flags&net.FlagLoopback != 0 {
- // loopback interface
- return false
- }
-
- if strings.Contains(strings.ToLower(face.Name), "docker") {
- return false
- }
-
- return true
-}
diff --git a/common/utils/net_test.go b/common/utils/net_test.go
deleted file mode 100644
index d50c437f8462f9ac8cc2b64df136d5d9aed67c8a..0000000000000000000000000000000000000000
--- a/common/utils/net_test.go
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package utils
-
-import (
- "testing"
-)
-
-import (
- "github.com/stretchr/testify/assert"
-)
-
-func TestGetLocalIP(t *testing.T) {
- ip, err := GetLocalIP()
- assert.NoError(t, err)
- t.Log(ip)
-}
diff --git a/common/utils/strings.go b/common/utils/strings.go
deleted file mode 100644
index ec5d118e9137f1818e1fe64ee3bc90d52080a3a8..0000000000000000000000000000000000000000
--- a/common/utils/strings.go
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package utils
-
-import (
- "regexp"
-)
-
-func RegSplit(text string, delimeter string) []string {
- reg := regexp.MustCompile(delimeter)
- indexes := reg.FindAllStringIndex(text, -1)
- laststart := 0
- result := make([]string, len(indexes)+1)
- for i, element := range indexes {
- result[i] = text[laststart:element[0]]
- laststart = element[1]
- }
- result[len(indexes)] = text[laststart:len(text)]
- return result
-}
diff --git a/common/utils/strings_test.go b/common/utils/strings_test.go
deleted file mode 100644
index 345ffd0c25d4398d63922115061697e148cb0a43..0000000000000000000000000000000000000000
--- a/common/utils/strings_test.go
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package utils
-
-import (
- "testing"
-)
-import (
- "github.com/stretchr/testify/assert"
-)
-
-func Test_RegSplit(t *testing.T) {
- strings := RegSplit("dubbo://123.1.2.1;jsonrpc://127.0.0.1;registry://3.2.1.3?registry=zookeeper", "\\s*[;]+\\s*")
- assert.Len(t, strings, 3)
- assert.Equal(t, "dubbo://123.1.2.1", strings[0])
- assert.Equal(t, "jsonrpc://127.0.0.1", strings[1])
- assert.Equal(t, "registry://3.2.1.3?registry=zookeeper", strings[2])
-}
diff --git a/config/protocol_config.go b/config/protocol_config.go
index b71423670c893402773ca2092d3d7a889a347439..2803456dbcd44211fb6deef883beb7f5dbbf54ad 100644
--- a/config/protocol_config.go
+++ b/config/protocol_config.go
@@ -37,8 +37,8 @@ func (c *ProtocolConfig) Prefix() string {
func loadProtocol(protocolsIds string, protocols map[string]*ProtocolConfig) []*ProtocolConfig {
returnProtocols := []*ProtocolConfig{}
for _, v := range strings.Split(protocolsIds, ",") {
- for _, prot := range protocols {
- if v == prot.Name {
+ for k, prot := range protocols {
+ if v == k {
returnProtocols = append(returnProtocols, prot)
}
}
diff --git a/config/reference_config.go b/config/reference_config.go
index 26976f1ccfad2185a4d3fe6b51dad411eb176099..c63ac2ef28ff85d07b76ad0f5fef669d83bca3a5 100644
--- a/config/reference_config.go
+++ b/config/reference_config.go
@@ -27,6 +27,7 @@ import (
import (
"github.com/creasty/defaults"
+ gxstrings "github.com/dubbogo/gost/strings"
)
import (
@@ -35,7 +36,6 @@ import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/common/proxy"
- "github.com/apache/dubbo-go/common/utils"
"github.com/apache/dubbo-go/protocol"
)
@@ -92,7 +92,7 @@ func (refconfig *ReferenceConfig) Refer() {
//1. user specified URL, could be peer-to-peer address, or register center's address.
if refconfig.Url != "" {
- urlStrings := utils.RegSplit(refconfig.Url, "\\s*[;]+\\s*")
+ urlStrings := gxstrings.RegSplit(refconfig.Url, "\\s*[;]+\\s*")
for _, urlStr := range urlStrings {
serviceUrl, err := common.NewURL(context.Background(), urlStr)
if err != nil {
diff --git a/config_center/configurator/override.go b/config_center/configurator/override.go
index 660c6ee315b299a9cf73d9399f572361adbafbd3..e85b4d3ec9d5e6f9f7163cefce3f328f8dcc225a 100644
--- a/config_center/configurator/override.go
+++ b/config_center/configurator/override.go
@@ -21,14 +21,14 @@ import (
)
import (
- "github.com/dubbogo/gost/container"
+ "github.com/dubbogo/gost/container/gxset"
+ gxnet "github.com/dubbogo/gost/net"
)
import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
- "github.com/apache/dubbo-go/common/utils"
"github.com/apache/dubbo-go/config_center"
)
@@ -59,7 +59,7 @@ func (c *overrideConfigurator) Configure(url *common.URL) {
currentSide := url.GetParam(constant.SIDE_KEY, "")
configuratorSide := c.configuratorUrl.GetParam(constant.SIDE_KEY, "")
if currentSide == configuratorSide && common.DubboRole[common.CONSUMER] == currentSide && c.configuratorUrl.Port == "0" {
- localIP, _ := utils.GetLocalIP()
+ localIP, _ := gxnet.GetLocalIP()
c.configureIfMatch(localIP, url)
} else if currentSide == configuratorSide && common.DubboRole[common.PROVIDER] == currentSide && c.configuratorUrl.Port == url.Port {
c.configureIfMatch(url.Ip, url)
@@ -78,7 +78,7 @@ func (c *overrideConfigurator) configureIfMatch(host string, url *common.URL) {
configApp := c.configuratorUrl.GetParam(constant.APPLICATION_KEY, c.configuratorUrl.Username)
currentApp := url.GetParam(constant.APPLICATION_KEY, url.Username)
if len(configApp) == 0 || constant.ANY_VALUE == configApp || configApp == currentApp {
- conditionKeys := container.NewSet()
+ conditionKeys := gxset.NewSet()
conditionKeys.Add(constant.CATEGORY_KEY)
conditionKeys.Add(constant.CHECK_KEY)
conditionKeys.Add(constant.ENABLED_KEY)
@@ -122,7 +122,7 @@ func (c *overrideConfigurator) configureDeprecated(url *common.URL) {
// 1.If it is a consumer ip address, the intention is to control a specific consumer instance, it must takes effect at the consumer side, any provider received this override url should ignore;
// 2.If the ip is 0.0.0.0, this override url can be used on consumer, and also can be used on provider
if url.GetParam(constant.SIDE_KEY, "") == common.DubboRole[common.CONSUMER] {
- localIP, _ := utils.GetLocalIP()
+ localIP, _ := gxnet.GetLocalIP()
c.configureIfMatch(localIP, url)
} else {
c.configureIfMatch(constant.ANYHOST_VALUE, url)
diff --git a/go.mod b/go.mod
index 09948c93c582feca5a3c8ee8df379e03bb6a4e84..be1c80bd170fe15a05eef55e013607265c282b2a 100644
--- a/go.mod
+++ b/go.mod
@@ -4,7 +4,7 @@ require (
github.com/Workiva/go-datastructures v1.0.50
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190802083043-4cd0c391755e // indirect
- github.com/apache/dubbo-go-hessian2 v1.2.5-0.20190909140437-80cbb25cbb22
+ github.com/apache/dubbo-go-hessian2 v1.2.5-0.20190923055845-e3dd5d131df5
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23 // indirect
github.com/coreos/bbolt v1.3.3 // indirect
github.com/coreos/etcd v3.3.13+incompatible
@@ -12,8 +12,8 @@ require (
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/creasty/defaults v1.3.0
- github.com/dubbogo/getty v1.2.2
- github.com/dubbogo/gost v1.1.1
+ github.com/dubbogo/getty v1.3.0
+ github.com/dubbogo/gost v1.3.0
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 // indirect
diff --git a/go.sum b/go.sum
index 8b92a8ff5eda0f93a95fd77497983b284f65a076..19b148133b736a6891ad2774db2f010a0b5691ca 100644
--- a/go.sum
+++ b/go.sum
@@ -35,8 +35,10 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190802083043-4cd0c391755e h1:MSuLXx/mveDbpDNhVrcWTMeV4lbYWKcyO4rH+jAxmX0=
github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190802083043-4cd0c391755e/go.mod h1:myCDvQSzCW+wB1WAlocEru4wMGJxy+vlxHdhegi1CDQ=
github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190307165228-86c17b95fcd5/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
-github.com/apache/dubbo-go-hessian2 v1.2.5-0.20190909140437-80cbb25cbb22 h1:Ku+3LFRYVelgo/INS9893QOUeIiKNeNKzK3CzDcqt/4=
-github.com/apache/dubbo-go-hessian2 v1.2.5-0.20190909140437-80cbb25cbb22/go.mod h1:LWnndnrFXZmJLAzoyNAPNHSIJ1KOHVkTSsHgC3YYWlo=
+github.com/apache/dubbo-go-hessian2 v1.2.5-0.20190921023740-335b8c601359 h1:ti5HOgxW/aKonsBe4Sj/W3+RMq4Jxl/EAAblROneggg=
+github.com/apache/dubbo-go-hessian2 v1.2.5-0.20190921023740-335b8c601359/go.mod h1:LWnndnrFXZmJLAzoyNAPNHSIJ1KOHVkTSsHgC3YYWlo=
+github.com/apache/dubbo-go-hessian2 v1.2.5-0.20190923055845-e3dd5d131df5 h1:p85EqnwOfcqqayW7OPREn0YJxIPIuEmuBJPezzhtO/M=
+github.com/apache/dubbo-go-hessian2 v1.2.5-0.20190923055845-e3dd5d131df5/go.mod h1:LWnndnrFXZmJLAzoyNAPNHSIJ1KOHVkTSsHgC3YYWlo=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e h1:QEF07wC0T1rKkctt1RINW/+RMTVmiwxETico2l3gxJA=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
@@ -102,10 +104,12 @@ github.com/docker/go-connections v0.3.0 h1:3lOnM9cSzgGwx8VfK/NGOW5fLQ0GjIlCkaktF
github.com/docker/go-connections v0.3.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.3.3 h1:Xk8S3Xj5sLGlG5g67hJmYMmUgXv5N4PhkjJHHqrwnTk=
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
-github.com/dubbogo/getty v1.2.2 h1:qDC9WXjxcs5NPvWZz2ruVKBKr2r1Jjm6i0Sq//CQwbE=
-github.com/dubbogo/getty v1.2.2/go.mod h1:K4b3MkGLf7T+lMgQNFgpg0dI1Wvv1PTisFs1Psf86kU=
+github.com/dubbogo/getty v1.3.0 h1:GImOCANdts7dlRqi9GMVsZJnfst9EPyjTVTR1AesOD8=
+github.com/dubbogo/getty v1.3.0/go.mod h1:K4b3MkGLf7T+lMgQNFgpg0dI1Wvv1PTisFs1Psf86kU=
github.com/dubbogo/gost v1.1.1 h1:JCM7vx5edPIjDA5ovJTuzEEXuw2t7xLyrlgi2mi5jHI=
github.com/dubbogo/gost v1.1.1/go.mod h1:R7wZm1DrmrKGr50mBZVcg6C9ekG8aL5hP+sgWcIDwQg=
+github.com/dubbogo/gost v1.3.0 h1:n90mIUWCPD69BqW8wJ43NDy0RgNxx02aAG4QJcJ785U=
+github.com/dubbogo/gost v1.3.0/go.mod h1:R7wZm1DrmrKGr50mBZVcg6C9ekG8aL5hP+sgWcIDwQg=
github.com/duosecurity/duo_api_golang v0.0.0-20190308151101-6c680f768e74 h1:2MIhn2R6oXQbgW5yHfS+d6YqyMfXiu2L55rFZC4UD/M=
github.com/duosecurity/duo_api_golang v0.0.0-20190308151101-6c680f768e74/go.mod h1:UqXY1lYT/ERa4OEAywUqdok1T4RCRdArkhic1Opuavo=
github.com/elazarl/go-bindata-assetfs v0.0.0-20160803192304-e1a2a7ec64b0 h1:ZoRgc53qJCfSLimXqJDrmBhnt5GChDsExMCK7t48o0Y=
@@ -184,7 +188,7 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGa
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
-github.com/gotestyourself/gotestyourself v2.2.0+incompatible h1:1yOKgt0XYKUg1HOKunGOSt2ocU4bxLCjmIHt0vRtVHM=
+github.com/gotestyourself/gotestyourself v2.2.0+incompatible h1:AQwinXlbQR2HvPjQZOmDhRqsv5mZf+Jb1RnSLxcqZcI=
github.com/gotestyourself/gotestyourself v2.2.0+incompatible/go.mod h1:zZKM6oeNM8k+FRljX1mnzVYeS8wiGgQyvST1/GafPbY=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 h1:pdN6V1QBWetyv/0+wjACpqVH+eVULgEjkurDLq3goeM=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
@@ -554,7 +558,7 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
-gotest.tools v2.2.0+incompatible h1:y0IMTfclpMdsdIbr6uwmJn5/WZ7vFuObxDMdrylFM3A=
+gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
diff --git a/protocol/dubbo/readwriter.go b/protocol/dubbo/readwriter.go
index a57c29f890cc76aa57b316aba8bead1bb76cf6ff..930382cca8bac6955b516a88e93ce26d73e235fe 100644
--- a/protocol/dubbo/readwriter.go
+++ b/protocol/dubbo/readwriter.go
@@ -68,20 +68,20 @@ func (p *RpcClientPackageHandler) Read(ss getty.Session, data []byte) (interface
return pkg, hessian.HEADER_LENGTH + pkg.Header.BodyLen, nil
}
-func (p *RpcClientPackageHandler) Write(ss getty.Session, pkg interface{}) error {
+func (p *RpcClientPackageHandler) Write(ss getty.Session, pkg interface{}) ([]byte, error) {
req, ok := pkg.(*DubboPackage)
if !ok {
logger.Errorf("illegal pkg:%+v\n", pkg)
- return perrors.New("invalid rpc request")
+ return nil, perrors.New("invalid rpc request")
}
buf, err := req.Marshal()
if err != nil {
logger.Warnf("binary.Write(req{%#v}) = err{%#v}", req, perrors.WithStack(err))
- return perrors.WithStack(err)
+ return nil, perrors.WithStack(err)
}
- return perrors.WithStack(ss.WriteBytes(buf.Bytes()))
+ return buf.Bytes(), nil
}
////////////////////////////////////////////
@@ -164,18 +164,18 @@ func (p *RpcServerPackageHandler) Read(ss getty.Session, data []byte) (interface
return pkg, hessian.HEADER_LENGTH + pkg.Header.BodyLen, nil
}
-func (p *RpcServerPackageHandler) Write(ss getty.Session, pkg interface{}) error {
+func (p *RpcServerPackageHandler) Write(ss getty.Session, pkg interface{}) ([]byte, error) {
res, ok := pkg.(*DubboPackage)
if !ok {
logger.Errorf("illegal pkg:%+v\n, it is %+v", pkg, reflect.TypeOf(pkg))
- return perrors.New("invalid rpc response")
+ return nil, perrors.New("invalid rpc response")
}
buf, err := res.Marshal()
if err != nil {
logger.Warnf("binary.Write(res{%#v}) = err{%#v}", res, perrors.WithStack(err))
- return perrors.WithStack(err)
+ return nil, perrors.WithStack(err)
}
- return perrors.WithStack(ss.WriteBytes(buf.Bytes()))
+ return buf.Bytes(), nil
}
diff --git a/registry/consul/utils.go b/registry/consul/utils.go
index ee17fcc0df43228e26b40f3ac3f992147fc33d6e..d295f644631ae63b6bdf035f71f5f104a64083e2 100644
--- a/registry/consul/utils.go
+++ b/registry/consul/utils.go
@@ -26,13 +26,13 @@ import (
)
import (
+ gxnet "github.com/dubbogo/gost/net"
consul "github.com/hashicorp/consul/api"
perrors "github.com/pkg/errors"
)
import (
"github.com/apache/dubbo-go/common"
- "github.com/apache/dubbo-go/common/utils"
)
func buildId(url common.URL) string {
@@ -48,7 +48,7 @@ func buildService(url common.URL) (*consul.AgentServiceRegistration, error) {
// address
if url.Ip == "" {
- url.Ip, _ = utils.GetLocalIP()
+ url.Ip, _ = gxnet.GetLocalIP()
}
// port
diff --git a/registry/etcdv3/registry.go b/registry/etcdv3/registry.go
index bf097f0b59573bc8d811015105065d6e2e1eb386..4ee90969e57fc50344c914f5332134e6f7f01b89 100644
--- a/registry/etcdv3/registry.go
+++ b/registry/etcdv3/registry.go
@@ -12,6 +12,7 @@ import (
)
import (
+ gxnet "github.com/dubbogo/gost/net"
perrors "github.com/pkg/errors"
)
@@ -20,7 +21,6 @@ import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/common/logger"
- "github.com/apache/dubbo-go/common/utils"
"github.com/apache/dubbo-go/registry"
"github.com/apache/dubbo-go/remoting/etcdv3"
)
@@ -37,7 +37,7 @@ const (
func init() {
processID = fmt.Sprintf("%d", os.Getpid())
- localIP, _ = utils.GetLocalIP()
+ localIP, _ = gxnet.GetLocalIP()
extension.SetRegistry(Name, newETCDV3Registry)
}
diff --git a/registry/nacos/registry.go b/registry/nacos/registry.go
index 229c6f8f0cea862b5ac676fe9d0d3f34cc6ed1b4..810a1cb05fec780868cf7767a9fcf8a7ccbd2b41 100644
--- a/registry/nacos/registry.go
+++ b/registry/nacos/registry.go
@@ -9,6 +9,7 @@ import (
)
import (
+ gxnet "github.com/dubbogo/gost/net"
"github.com/nacos-group/nacos-sdk-go/clients"
"github.com/nacos-group/nacos-sdk-go/clients/naming_client"
nacosConstant "github.com/nacos-group/nacos-sdk-go/common/constant"
@@ -21,7 +22,6 @@ import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/common/logger"
- "github.com/apache/dubbo-go/common/utils"
"github.com/apache/dubbo-go/registry"
)
@@ -34,7 +34,7 @@ const (
)
func init() {
- localIP, _ = utils.GetLocalIP()
+ localIP, _ = gxnet.GetLocalIP()
extension.SetRegistry(constant.NACOS_KEY, newNacosRegistry)
}
diff --git a/registry/protocol/protocol.go b/registry/protocol/protocol.go
index d1e02b11b21396d7963d2cfffb8e1211b6ee6666..534a4b945965f332e49ff343557fa20355921454 100644
--- a/registry/protocol/protocol.go
+++ b/registry/protocol/protocol.go
@@ -23,7 +23,7 @@ import (
)
import (
- "github.com/dubbogo/gost/container"
+ "github.com/dubbogo/gost/container/gxset"
)
import (
@@ -65,7 +65,7 @@ func init() {
func getCacheKey(url *common.URL) string {
newUrl := url.Clone()
- delKeys := container.NewSet("dynamic", "enabled")
+ delKeys := gxset.NewSet("dynamic", "enabled")
newUrl.RemoveParams(delKeys)
return newUrl.String()
}
@@ -174,7 +174,7 @@ func (proto *registryProtocol) Export(invoker protocol.Invoker) protocol.Exporte
logger.Infof("The exporter has not been cached, and will return a new exporter!")
}
- reg.Subscribe(overriderUrl, overrideSubscribeListener)
+ go reg.Subscribe(overriderUrl, overrideSubscribeListener)
return cachedExporter.(protocol.Exporter)
}
diff --git a/registry/zookeeper/registry.go b/registry/zookeeper/registry.go
index 972a4b6c5e0af7e53e9aad6df33209d15f71a587..29ae51d44f3691807cbc74912290ba141d1f5d47 100644
--- a/registry/zookeeper/registry.go
+++ b/registry/zookeeper/registry.go
@@ -29,6 +29,7 @@ import (
)
import (
+ gxnet "github.com/dubbogo/gost/net"
perrors "github.com/pkg/errors"
"github.com/samuel/go-zookeeper/zk"
)
@@ -38,7 +39,6 @@ import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/common/logger"
- "github.com/apache/dubbo-go/common/utils"
"github.com/apache/dubbo-go/registry"
"github.com/apache/dubbo-go/remoting/zookeeper"
)
@@ -55,7 +55,7 @@ var (
func init() {
processID = fmt.Sprintf("%d", os.Getpid())
- localIP, _ = utils.GetLocalIP()
+ localIP, _ = gxnet.GetLocalIP()
//plugins.PluggableRegistries["zookeeper"] = newZkRegistry
extension.SetRegistry("zookeeper", newZkRegistry)
}