Select is a better method
This commit is contained in:
parent
727bba15b8
commit
3d279ffcfd
@ -16,7 +16,7 @@ import (
|
|||||||
// response from a client call. Reset is called to zero out
|
// response from a client call. Reset is called to zero out
|
||||||
// any state.
|
// any state.
|
||||||
type NodeSelector interface {
|
type NodeSelector interface {
|
||||||
Retrieve(context.Context, Request) (*registry.Node, error)
|
Select(context.Context, Request) (*registry.Node, error)
|
||||||
Response(*registry.Node, error)
|
Response(*registry.Node, error)
|
||||||
Reset()
|
Reset()
|
||||||
}
|
}
|
||||||
@ -30,7 +30,7 @@ type nodeSelector struct {
|
|||||||
r registry.Registry
|
r registry.Registry
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *nodeSelector) Retrieve(ctx context.Context, req Request) (*registry.Node, error) {
|
func (n *nodeSelector) Select(ctx context.Context, req Request) (*registry.Node, error) {
|
||||||
service, err := n.r.GetService(req.Service())
|
service, err := n.r.GetService(req.Service())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.InternalServerError("go.micro.client", err.Error())
|
return nil, errors.InternalServerError("go.micro.client", err.Error())
|
||||||
|
@ -59,7 +59,7 @@ func TestNodeSelector(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
n, err := n.Retrieve(context.Background(), newRpcRequest("foo", "Foo.Bar", nil, ""))
|
n, err := n.Select(context.Background(), newRpcRequest("foo", "Foo.Bar", nil, ""))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Expected node, got err: %v", err)
|
t.Errorf("Expected node, got err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ func (r *rpcClient) CallRemote(ctx context.Context, address string, request Requ
|
|||||||
|
|
||||||
// TODO: Call(..., opts *Options) error {
|
// TODO: Call(..., opts *Options) error {
|
||||||
func (r *rpcClient) Call(ctx context.Context, request Request, response interface{}) error {
|
func (r *rpcClient) Call(ctx context.Context, request Request, response interface{}) error {
|
||||||
node, err := r.sel.Retrieve(ctx, request)
|
node, err := r.sel.Select(ctx, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -174,7 +174,7 @@ func (r *rpcClient) StreamRemote(ctx context.Context, address string, request Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *rpcClient) Stream(ctx context.Context, request Request, responseChan interface{}) (Streamer, error) {
|
func (r *rpcClient) Stream(ctx context.Context, request Request, responseChan interface{}) (Streamer, error) {
|
||||||
node, err := r.sel.Retrieve(ctx, request)
|
node, err := r.sel.Select(ctx, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ type nodeSelector struct {
|
|||||||
r registry.Registry
|
r registry.Registry
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *nodeSelector) Retrieve(ctx context.Context, req client.Request) (*registry.Node, error) {
|
func (n *nodeSelector) Select(ctx context.Context, req client.Request) (*registry.Node, error) {
|
||||||
service, err := n.r.GetService(req.Service())
|
service, err := n.r.GetService(req.Service())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.InternalServerError("go.micro.client", err.Error())
|
return nil, errors.InternalServerError("go.micro.client", err.Error())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user