Port in header X-Forwarded-Port has highest priority (#39)

upgrade go chassis
diff --git a/adminapi/health/health_test.go b/adminapi/health/health_test.go
index ba1aefd..fc30b5e 100644
--- a/adminapi/health/health_test.go
+++ b/adminapi/health/health_test.go
@@ -19,7 +19,7 @@
 
 import (
 	"errors"
-	"github.com/go-chassis/go-cc-client/configcenter-client"
+	"github.com/go-chassis/go-cc-client/configcenter"
 	"github.com/go-chassis/go-chassis/core/config"
 	"github.com/go-chassis/go-chassis/core/config/model"
 	"github.com/go-chassis/go-chassis/core/lager"
@@ -112,7 +112,7 @@
 	t.Log("config center connected")
 
 	testMemberDiscoverObj := new(MockMemberDiscovery)
-	configcenterclient.MemberDiscoveryService = testMemberDiscoverObj
+	configcenter.MemberDiscoveryService = testMemberDiscoverObj
 	testMemberDiscoverObj.On("RefreshMembers").Return(nil)
 	testMemberDiscoverObj.On("GetConfigServer").Return([]string{"localhost:8080"}, nil)
 	assert.True(t, isConfigCenterConnected())
@@ -123,7 +123,7 @@
 	t.Log("config center not connected")
 
 	testMemberDiscoverObj := new(MockMemberDiscovery)
-	configcenterclient.MemberDiscoveryService = testMemberDiscoverObj
+	configcenter.MemberDiscoveryService = testMemberDiscoverObj
 	testMemberDiscoverObj.On("GetConfigServer").Return([]string{"2.2.2.2:2222"}, mockError)
 	assert.False(t, isConfigCenterConnected())
 }
diff --git a/adminapi/health/instances.go b/adminapi/health/instances.go
index cd4944f..caf2ae3 100644
--- a/adminapi/health/instances.go
+++ b/adminapi/health/instances.go
@@ -23,7 +23,7 @@
 
 	ver "github.com/go-mesh/mesher/adminapi/version"
 
-	"github.com/go-chassis/go-cc-client/configcenter-client"
+	"github.com/go-chassis/go-cc-client/configcenter"
 	"github.com/go-chassis/go-chassis/core/config"
 	"github.com/go-chassis/go-chassis/core/lager"
 	"github.com/go-chassis/go-chassis/core/registry"
@@ -84,12 +84,12 @@
 }
 
 func isConfigCenterConnected() bool {
-	if configcenterclient.MemberDiscoveryService == nil {
+	if configcenter.MemberDiscoveryService == nil {
 		return false
 	}
 
 	// Getting config center ip's using refresh members handled in GetConfigServer function based on Autodiscovery
-	configServerHosts, err := configcenterclient.MemberDiscoveryService.GetConfigServer()
+	configServerHosts, err := configcenter.MemberDiscoveryService.GetConfigServer()
 	if err != nil || len(configServerHosts) == 0 {
 		return false
 	}
diff --git a/go.mod b/go.mod
index c3983db..3393d04 100644
--- a/go.mod
+++ b/go.mod
@@ -5,31 +5,30 @@
 	github.com/emicklei/go-restful-swagger12 v0.0.0-20170926063155-7524189396c6 // indirect
 	github.com/envoyproxy/go-control-plane v0.6.0
 	github.com/ghodss/yaml v1.0.0 // indirect
-	github.com/go-chassis/go-archaius v0.0.0-20181119064113-720d998498f3
-
-	github.com/go-chassis/go-cc-client v0.0.0-20181102101915-dea430061a34
-	github.com/go-chassis/go-chassis v1.1.3
+	github.com/go-chassis/foundation v0.0.0-20190203091418-304855ea28bf
+	github.com/go-chassis/go-archaius v0.7.0
+	github.com/go-chassis/go-chassis v1.2.3-0.20190219012152-d772c486613a
 	github.com/go-chassis/gohessian v0.0.0-20180702061429-e5130c25af55
 	github.com/go-mesh/openlogging v0.0.0-20181122085847-3daf3ad8ed35
 	github.com/gogo/googleapis v1.1.0 // indirect
-	github.com/gogo/protobuf v1.1.1
-	github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
+	github.com/gogo/protobuf v1.2.0
+	github.com/golang/snappy v0.0.1 // indirect
 	github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
 	github.com/imdario/mergo v0.3.6 // indirect
 	github.com/lyft/protoc-gen-validate v0.0.11 // indirect
 	github.com/onsi/gomega v1.4.2 // indirect
 	github.com/patrickmn/go-cache v2.1.0+incompatible
-	github.com/prometheus/client_golang v0.8.0
-	github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910
+	github.com/prometheus/client_golang v0.9.1
+	github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f
+	github.com/spf13/pflag v1.0.3 // indirect
 	github.com/stretchr/testify v1.2.2
 	github.com/uber-go/atomic v1.3.2 // indirect
 	github.com/urfave/cli v1.20.1-0.20181029213200-b67dcf995b6a
 	go.uber.org/atomic v1.3.2 // indirect
 	golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16 // indirect
-	golang.org/x/net v0.0.0-20180906233101-161cd47e91fd
+	golang.org/x/net v0.0.0-20181114220301-adae6a3d119a
 	golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 // indirect
-	google.golang.org/genproto v0.0.0-20181101192439-c830210a61df // indirect
-	google.golang.org/grpc v1.14.0
+	google.golang.org/grpc v1.16.0
 	gopkg.in/inf.v0 v0.9.1 // indirect
 	gopkg.in/yaml.v2 v2.2.1
 	k8s.io/apimachinery v0.0.0-20181022183627-f71dbbc36e12
diff --git a/health/l7check.go b/health/l7check.go
index 71e2622..a3dfc72 100644
--- a/health/l7check.go
+++ b/health/l7check.go
@@ -2,8 +2,8 @@
 
 import (
 	"errors"
+	"github.com/go-chassis/foundation/httpclient"
 	"github.com/go-chassis/go-chassis/core/lager"
-	"github.com/go-chassis/go-chassis/pkg/httpclient"
 	"github.com/go-mesh/mesher/config"
 	"io/ioutil"
 	"net/http"
diff --git a/pkg/metrics/prom_recorder.go b/pkg/metrics/prom_recorder.go
index a1bc62d..00eccb7 100644
--- a/pkg/metrics/prom_recorder.go
+++ b/pkg/metrics/prom_recorder.go
@@ -4,7 +4,6 @@
 	"errors"
 	"github.com/prometheus/client_golang/prometheus"
 	"net/http"
-	"os"
 	"sync"
 	"time"
 )
@@ -21,7 +20,7 @@
 	if opts != nil {
 		if opts.EnableGoRuntimeMetrics {
 			onceEnable.Do(func() {
-				promConfig.PromRegistry.MustRegister(prometheus.NewProcessCollector(os.Getpid(), ""))
+				promConfig.PromRegistry.MustRegister(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}))
 				promConfig.PromRegistry.MustRegister(prometheus.NewGoCollector())
 			})
 		}
diff --git a/protocol/dubbo/proxy/dubbo_proxy_ouput.go b/protocol/dubbo/proxy/dubbo_proxy_ouput.go
index 276a651..919bb5b 100755
--- a/protocol/dubbo/proxy/dubbo_proxy_ouput.go
+++ b/protocol/dubbo/proxy/dubbo_proxy_ouput.go
@@ -31,8 +31,8 @@
 	"github.com/go-chassis/go-chassis/core/invocation"
 	"github.com/go-chassis/go-chassis/core/lager"
 	"github.com/go-chassis/go-chassis/core/loadbalancer"
-	"github.com/go-chassis/go-chassis/core/util/string"
 	"github.com/go-chassis/go-chassis/pkg/runtime"
+	"github.com/go-chassis/go-chassis/pkg/string"
 	"github.com/go-chassis/go-chassis/pkg/util/httputil"
 	"github.com/go-chassis/go-chassis/pkg/util/tags"
 	"github.com/go-chassis/go-chassis/third_party/forked/afex/hystrix-go/hystrix"
diff --git a/protocol/dubbo/proxy/rest2dubbo.go b/protocol/dubbo/proxy/rest2dubbo.go
index 8f3008b..ae4c6cf 100755
--- a/protocol/dubbo/proxy/rest2dubbo.go
+++ b/protocol/dubbo/proxy/rest2dubbo.go
@@ -36,7 +36,7 @@
 	"github.com/go-chassis/go-chassis/core/invocation"
 	"github.com/go-chassis/go-chassis/core/lager"
 	"github.com/go-chassis/go-chassis/core/loadbalancer"
-	"github.com/go-chassis/go-chassis/core/util/string"
+	"github.com/go-chassis/go-chassis/pkg/string"
 	"github.com/go-chassis/go-chassis/pkg/util/tags"
 	"github.com/go-chassis/go-chassis/third_party/forked/afex/hystrix-go/hystrix"
 	"github.com/go-mesh/mesher/protocol"
diff --git a/protocol/grpc/reverse_proxy.go b/protocol/grpc/reverse_proxy.go
index e11d0ee..904fe9e 100755
--- a/protocol/grpc/reverse_proxy.go
+++ b/protocol/grpc/reverse_proxy.go
@@ -31,14 +31,14 @@
 	"github.com/go-chassis/go-chassis/core/handler"
 	"github.com/go-chassis/go-chassis/core/invocation"
 	"github.com/go-chassis/go-chassis/core/lager"
-	"github.com/go-chassis/go-chassis/core/util/string"
 	"github.com/go-chassis/go-chassis/pkg/runtime"
+	"github.com/go-chassis/go-chassis/pkg/string"
 	"github.com/go-chassis/go-chassis/pkg/util/tags"
-	"github.com/go-mesh/mesher/cmd"
 	"github.com/go-mesh/mesher/common"
 	"github.com/go-mesh/mesher/pkg/metrics"
 	"github.com/go-mesh/mesher/protocol"
 	"github.com/go-mesh/mesher/resolver"
+	"github.com/go-mesh/mesher/util"
 	"github.com/go-mesh/openlogging"
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/status"
@@ -171,7 +171,7 @@
 		lager.Logger.Error("Get chain failed: " + err.Error())
 		return
 	}
-	if err = SetLocalServiceAddress(inv, r.Header.Get("X-Forwarded-Port")); err != nil {
+	if err = util.SetLocalServiceAddress(inv, r.Header.Get("X-Forwarded-Port")); err != nil {
 		WriteErrorResponse(inv, w, r, http.StatusBadGateway,
 			err)
 	}
@@ -192,22 +192,6 @@
 	}
 }
 
-//SetLocalServiceAddress assign invocation endpoint a local service address
-// it uses config in cmd or env fi
-// if it is empty, then try to use original port from client as local port
-func SetLocalServiceAddress(inv *invocation.Invocation, port string) error {
-	inv.Endpoint = cmd.Configs.PortsMap[inv.Protocol]
-	if inv.Endpoint == "" {
-		if port != "" {
-			inv.Endpoint = "127.0.0.1:" + port
-			return nil
-		} else {
-			return fmt.Errorf("[%s] is not supported, [%s] didn't set env [%s] or cmd parameter --service-ports before mesher start",
-				inv.Protocol, inv.MicroServiceName, common.EnvServicePorts)
-		}
-	}
-	return nil
-}
 func copyChassisResp2HttpResp(w http.ResponseWriter, resp *http.Response) {
 	if resp == nil || resp.StatusCode == 0 {
 		lager.Logger.Warn("response is nil or empty because of unknown reason, plz report issue")
diff --git a/protocol/http/reverse_proxy.go b/protocol/http/reverse_proxy.go
index 2ec0a5e..536c074 100755
--- a/protocol/http/reverse_proxy.go
+++ b/protocol/http/reverse_proxy.go
@@ -24,7 +24,6 @@
 	"net/http"
 	"time"
 
-	"fmt"
 	"github.com/go-chassis/go-chassis/client/rest"
 	chassisCommon "github.com/go-chassis/go-chassis/core/common"
 	chassisconfig "github.com/go-chassis/go-chassis/core/config"
@@ -33,16 +32,16 @@
 	"github.com/go-chassis/go-chassis/core/invocation"
 	"github.com/go-chassis/go-chassis/core/lager"
 	"github.com/go-chassis/go-chassis/core/loadbalancer"
-	"github.com/go-chassis/go-chassis/core/util/string"
 	"github.com/go-chassis/go-chassis/pkg/runtime"
+	"github.com/go-chassis/go-chassis/pkg/string"
 	"github.com/go-chassis/go-chassis/pkg/util/tags"
 	"github.com/go-chassis/go-chassis/third_party/forked/afex/hystrix-go/hystrix"
-	"github.com/go-mesh/mesher/cmd"
 	"github.com/go-mesh/mesher/common"
 	"github.com/go-mesh/mesher/pkg/egress"
 	"github.com/go-mesh/mesher/pkg/metrics"
 	"github.com/go-mesh/mesher/protocol"
 	"github.com/go-mesh/mesher/resolver"
+	util "github.com/go-mesh/mesher/util"
 	"github.com/go-mesh/openlogging"
 	"strconv"
 	"strings"
@@ -191,7 +190,7 @@
 		lager.Logger.Error("Get chain failed: " + err.Error())
 		return
 	}
-	if err = SetLocalServiceAddress(inv, r.Header.Get("X-Forwarded-Port")); err != nil {
+	if err = util.SetLocalServiceAddress(inv, r.Header.Get("X-Forwarded-Port")); err != nil {
 		handleErrorResponse(inv, w, http.StatusBadGateway,
 			err)
 	}
@@ -212,22 +211,6 @@
 	}
 }
 
-//SetLocalServiceAddress assign invocation endpoint a local service address
-// it uses config in cmd or env fi
-// if it is empty, then try to use original port from client as local port
-func SetLocalServiceAddress(inv *invocation.Invocation, port string) error {
-	inv.Endpoint = cmd.Configs.PortsMap[inv.Protocol]
-	if inv.Endpoint == "" {
-		if port != "" {
-			inv.Endpoint = "127.0.0.1:" + port
-			return nil
-		} else {
-			return fmt.Errorf("[%s] is not supported, [%s] didn't set env [%s] or cmd parameter --service-ports before mesher start",
-				inv.Protocol, inv.MicroServiceName, common.EnvServicePorts)
-		}
-	}
-	return nil
-}
 func copyChassisResp2HttpResp(w http.ResponseWriter, resp *http.Response) {
 	postProcessResponse(resp)
 	copyHeader(w.Header(), resp.Header)
diff --git a/util/util.go b/util/util.go
new file mode 100644
index 0000000..959bb01
--- /dev/null
+++ b/util/util.go
@@ -0,0 +1,26 @@
+package util
+
+import (
+	"fmt"
+	"github.com/go-chassis/go-chassis/core/invocation"
+	"github.com/go-mesh/mesher/cmd"
+	"github.com/go-mesh/mesher/common"
+)
+
+//SetLocalServiceAddress assign invocation endpoint a local service address
+//header "X-Forwarded-Port" has highest priority
+// if it is empty
+// it uses ports config in cmd param or env
+func SetLocalServiceAddress(inv *invocation.Invocation, port string) error {
+	inv.Endpoint = cmd.Configs.PortsMap[inv.Protocol]
+	if port == "" {
+		inv.Endpoint = cmd.Configs.PortsMap[inv.Protocol]
+		if inv.Endpoint == "" {
+			return fmt.Errorf("[%s] is not supported, [%s] didn't set env [%s] or cmd parameter --service-ports before mesher start",
+				inv.Protocol, inv.MicroServiceName, common.EnvServicePorts)
+		}
+		return nil
+	}
+	inv.Endpoint = "127.0.0.1:" + port
+	return nil
+}
diff --git a/protocol/http/reverse_proxy_test.go b/util/util_test.go
similarity index 67%
rename from protocol/http/reverse_proxy_test.go
rename to util/util_test.go
index 041db04..5c5013a 100755
--- a/protocol/http/reverse_proxy_test.go
+++ b/util/util_test.go
@@ -15,12 +15,12 @@
  * limitations under the License.
  */
 
-package http_test
+package util_test
 
 import (
 	"github.com/go-chassis/go-chassis/core/invocation"
 	"github.com/go-mesh/mesher/cmd"
-	"github.com/go-mesh/mesher/protocol/http"
+	"github.com/go-mesh/mesher/util"
 	"github.com/stretchr/testify/assert"
 	"testing"
 )
@@ -33,18 +33,36 @@
 
 	inv := invocation.New(nil)
 	inv.Protocol = "rest"
-	err = http.SetLocalServiceAddress(inv, "8080")
+	err = util.SetLocalServiceAddress(inv, "8080")
 	assert.NoError(t, err)
 	assert.Equal(t, "127.0.0.1:8080", inv.Endpoint)
 
-	err = http.SetLocalServiceAddress(inv, "")
+	err = util.SetLocalServiceAddress(inv, "")
 	assert.Error(t, err)
 
+	t.Log("header has highest priority")
 	cmd.Configs.LocalServicePorts = "rest:80"
 	err = cmd.Configs.GeneratePortsMap()
 	t.Log(cmd.Configs.PortsMap)
 	assert.NoError(t, err)
-	err = http.SetLocalServiceAddress(inv, "")
+	err = util.SetLocalServiceAddress(inv, "8080")
+	assert.NoError(t, err)
+	assert.Equal(t, "127.0.0.1:8080", inv.Endpoint)
+
+	t.Log("env and param has lower priority")
+	err = util.SetLocalServiceAddress(inv, "")
 	assert.NoError(t, err)
 	assert.Equal(t, "127.0.0.1:80", inv.Endpoint)
+
+	t.Log("missing env or param")
+	inv.Protocol = "grpc"
+	err = util.SetLocalServiceAddress(inv, "")
+	assert.Error(t, err)
+
+	t.Log("specify port env or param")
+	inv.Protocol = "grpc"
+	err = util.SetLocalServiceAddress(inv, "9090")
+	assert.NoError(t, err)
+	assert.Equal(t, "127.0.0.1:9090", inv.Endpoint)
+
 }