parent
dfd784d4fa
commit
e9db13acab
22
grpc.go
22
grpc.go
@ -6,7 +6,6 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@ -20,6 +19,7 @@ import (
|
|||||||
"github.com/micro/go-micro/v2/metadata"
|
"github.com/micro/go-micro/v2/metadata"
|
||||||
"github.com/micro/go-micro/v2/registry"
|
"github.com/micro/go-micro/v2/registry"
|
||||||
"github.com/micro/go-micro/v2/util/config"
|
"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"
|
||||||
"google.golang.org/grpc/credentials"
|
"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) {
|
func (g *grpcClient) next(request client.Request, opts client.CallOptions) (selector.Next, error) {
|
||||||
service := request.Service()
|
service, address, _ := pnet.Proxy(request.Service(), opts.Address)
|
||||||
|
|
||||||
// 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}
|
|
||||||
}
|
|
||||||
|
|
||||||
// return remote address
|
// return remote address
|
||||||
if len(opts.Address) > 0 {
|
if len(address) > 0 {
|
||||||
return func() (*registry.Node, error) {
|
return func() (*registry.Node, error) {
|
||||||
return ®istry.Node{
|
return ®istry.Node{
|
||||||
Address: opts.Address[0],
|
Address: address[0],
|
||||||
}, nil
|
}, nil
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user