@@ -20,6 +20,7 @@ import (
2020 "go.unistack.org/micro/v3/codec"
2121 "go.unistack.org/micro/v3/errors"
2222 "go.unistack.org/micro/v3/metadata"
23+ "go.unistack.org/micro/v3/selector"
2324 rutil "go.unistack.org/micro/v3/util/reflect"
2425)
2526
@@ -386,18 +387,7 @@ func (h *httpClient) Call(ctx context.Context, req client.Request, rsp interface
386387 callOpts .Address = []string {h .opts .Proxy }
387388 }
388389
389- // lookup the route to send the reques to
390- // TODO apply any filtering here
391- routes , err := h .opts .Lookup (ctx , req , callOpts )
392- if err != nil {
393- return errors .InternalServerError ("go.micro.client" , err .Error ())
394- }
395-
396- // balance the list of nodes
397- next , err := callOpts .Selector .Select (routes )
398- if err != nil {
399- return err
400- }
390+ var next selector.Next
401391
402392 // return errors.New("go.micro.client", "request timeout", 408)
403393 call := func (i int ) error {
@@ -412,6 +402,22 @@ func (h *httpClient) Call(ctx context.Context, req client.Request, rsp interface
412402 time .Sleep (t )
413403 }
414404
405+ if next == nil {
406+ var routes []string
407+ // lookup the route to send the reques to
408+ // TODO apply any filtering here
409+ routes , err = h .opts .Lookup (ctx , req , callOpts )
410+ if err != nil {
411+ return errors .InternalServerError ("go.micro.client" , err .Error ())
412+ }
413+
414+ // balance the list of nodes
415+ next , err = callOpts .Selector .Select (routes )
416+ if err != nil {
417+ return err
418+ }
419+ }
420+
415421 node := next ()
416422
417423 // make the call
@@ -463,6 +469,8 @@ func (h *httpClient) Call(ctx context.Context, req client.Request, rsp interface
463469}
464470
465471func (h * httpClient ) Stream (ctx context.Context , req client.Request , opts ... client.CallOption ) (client.Stream , error ) {
472+ var err error
473+
466474 // make a copy of call opts
467475 callOpts := h .opts .CallOptions
468476 for _ , o := range opts {
@@ -514,18 +522,7 @@ func (h *httpClient) Stream(ctx context.Context, req client.Request, opts ...cli
514522 callOpts .Address = []string {h .opts .Proxy }
515523 }
516524
517- // lookup the route to send the reques to
518- // TODO apply any filtering here
519- routes , err := h .opts .Lookup (ctx , req , callOpts )
520- if err != nil {
521- return nil , errors .InternalServerError ("go.micro.client" , err .Error ())
522- }
523-
524- // balance the list of nodes
525- next , err := callOpts .Selector .Select (routes )
526- if err != nil {
527- return nil , err
528- }
525+ var next selector.Next
529526
530527 call := func (i int ) (client.Stream , error ) {
531528 // call backoff first. Someone may want an initial start delay
@@ -539,6 +536,22 @@ func (h *httpClient) Stream(ctx context.Context, req client.Request, opts ...cli
539536 time .Sleep (t )
540537 }
541538
539+ if next == nil {
540+ var routes []string
541+ // lookup the route to send the reques to
542+ // TODO apply any filtering here
543+ routes , err = h .opts .Lookup (ctx , req , callOpts )
544+ if err != nil {
545+ return nil , errors .InternalServerError ("go.micro.client" , err .Error ())
546+ }
547+
548+ // balance the list of nodes
549+ next , err = callOpts .Selector .Select (routes )
550+ if err != nil {
551+ return nil , err
552+ }
553+ }
554+
542555 node := next ()
543556
544557 stream , cerr := h .stream (ctx , node , req , callOpts )
0 commit comments