Accept a range of addresses
This commit is contained in:
parent
940ea94a96
commit
0da8256426
@ -59,14 +59,14 @@ func (g *grpcClient) next(request client.Request, opts client.CallOptions) (sele
|
|||||||
|
|
||||||
// get proxy address
|
// get proxy address
|
||||||
if prx := os.Getenv("MICRO_PROXY_ADDRESS"); len(prx) > 0 {
|
if prx := os.Getenv("MICRO_PROXY_ADDRESS"); len(prx) > 0 {
|
||||||
opts.Address = prx
|
opts.Address = []string{prx}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return remote address
|
// return remote address
|
||||||
if len(opts.Address) > 0 {
|
if len(opts.Address) > 0 {
|
||||||
return func() (*registry.Node, error) {
|
return func() (*registry.Node, error) {
|
||||||
return ®istry.Node{
|
return ®istry.Node{
|
||||||
Address: opts.Address,
|
Address: opts.Address[0],
|
||||||
}, nil
|
}, nil
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,8 @@ type Options struct {
|
|||||||
type CallOptions struct {
|
type CallOptions struct {
|
||||||
SelectOptions []selector.SelectOption
|
SelectOptions []selector.SelectOption
|
||||||
|
|
||||||
// Address of remote host
|
// Address of remote hosts
|
||||||
Address string
|
Address []string
|
||||||
// Backoff func
|
// Backoff func
|
||||||
Backoff BackoffFunc
|
Backoff BackoffFunc
|
||||||
// Check if retriable func
|
// Check if retriable func
|
||||||
@ -245,8 +245,8 @@ func WithExchange(e string) PublishOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithAddress sets the remote address to use rather than using service discovery
|
// WithAddress sets the remote addresses to use rather than using service discovery
|
||||||
func WithAddress(a string) CallOption {
|
func WithAddress(a ...string) CallOption {
|
||||||
return func(o *CallOptions) {
|
return func(o *CallOptions) {
|
||||||
o.Address = a
|
o.Address = a
|
||||||
}
|
}
|
||||||
|
@ -283,29 +283,36 @@ func (r *rpcClient) next(request Request, opts CallOptions) (selector.Next, erro
|
|||||||
|
|
||||||
// get proxy address
|
// get proxy address
|
||||||
if prx := os.Getenv("MICRO_PROXY_ADDRESS"); len(prx) > 0 {
|
if prx := os.Getenv("MICRO_PROXY_ADDRESS"); len(prx) > 0 {
|
||||||
opts.Address = prx
|
opts.Address = []string{prx}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return remote address
|
// return remote address
|
||||||
if len(opts.Address) > 0 {
|
if len(opts.Address) > 0 {
|
||||||
address := opts.Address
|
var nodes []*registry.Node
|
||||||
port := 0
|
|
||||||
|
|
||||||
host, sport, err := net.SplitHostPort(opts.Address)
|
for _, addr := range opts.Address {
|
||||||
if err == nil {
|
address := addr
|
||||||
address = host
|
port := 0
|
||||||
port, _ = strconv.Atoi(sport)
|
|
||||||
}
|
|
||||||
|
|
||||||
return func() (*registry.Node, error) {
|
host, sport, err := net.SplitHostPort(addr)
|
||||||
return ®istry.Node{
|
if err == nil {
|
||||||
|
address = host
|
||||||
|
port, _ = strconv.Atoi(sport)
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes = append(nodes, ®istry.Node{
|
||||||
Address: address,
|
Address: address,
|
||||||
Port: port,
|
Port: port,
|
||||||
// Set the protocol
|
// Set the protocol
|
||||||
Metadata: map[string]string{
|
Metadata: map[string]string{
|
||||||
"protocol": "mucp",
|
"protocol": "mucp",
|
||||||
},
|
},
|
||||||
}, nil
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// crude return method
|
||||||
|
return func() (*registry.Node, error) {
|
||||||
|
return nodes[time.Now().Unix()%int64(len(nodes))], nil
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user