From e9db13acab4bc1445e864c6ce2ad247b275b517b Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 21 Apr 2020 15:54:40 +0100 Subject: [PATCH] Add network proxying (#1556) * Add network proxying * go fmt --- grpc.go | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/grpc.go b/grpc.go index 30dd97f..d41d977 100644 --- a/grpc.go +++ b/grpc.go @@ -6,7 +6,6 @@ import ( "crypto/tls" "fmt" "net" - "os" "strings" "sync/atomic" "time" @@ -20,6 +19,7 @@ import ( "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/registry" "github.com/micro/go-micro/v2/util/config" + pnet "github.com/micro/go-micro/v2/util/net" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -74,27 +74,13 @@ func (g *grpcClient) secure(addr string) grpc.DialOption { } func (g *grpcClient) next(request client.Request, opts client.CallOptions) (selector.Next, error) { - service := request.Service() - - // get proxy - if prx := os.Getenv("MICRO_PROXY"); len(prx) > 0 { - // default name - if prx == "service" { - prx = "go.micro.proxy" - } - service = prx - } - - // get proxy address - if prx := os.Getenv("MICRO_PROXY_ADDRESS"); len(prx) > 0 { - opts.Address = []string{prx} - } + service, address, _ := pnet.Proxy(request.Service(), opts.Address) // return remote address - if len(opts.Address) > 0 { + if len(address) > 0 { return func() (*registry.Node, error) { return ®istry.Node{ - Address: opts.Address[0], + Address: address[0], }, nil }, nil }