diff --git a/client/grpc/grpc.go b/client/grpc/grpc.go index b57b0829..3dc91523 100644 --- a/client/grpc/grpc.go +++ b/client/grpc/grpc.go @@ -114,7 +114,7 @@ func (g *grpcClient) lookupRoute(req client.Request, opts client.CallOptions) (* } // select the route to use for the request - if route, err := opts.Selector.Select(routes); err == selector.ErrNoneAvailable { + if route, err := opts.Selector.Select(routes, opts.SelectOptions...); err == selector.ErrNoneAvailable { return nil, errors.InternalServerError("go.micro.client", "service %s: %s", req.Service(), err.Error()) } else if err != nil { return nil, errors.InternalServerError("go.micro.client", "error getting next %s node: %s", req.Service(), err.Error()) diff --git a/client/options.go b/client/options.go index cfc3ab23..5058983d 100644 --- a/client/options.go +++ b/client/options.go @@ -60,6 +60,8 @@ type CallOptions struct { Router router.Router // Selector to use for the call Selector selector.Selector + // SelectOptions to use when selecting a route + SelectOptions []selector.SelectOption // Stream timeout for the stream StreamTimeout time.Duration // Use the services own auth token @@ -360,6 +362,13 @@ func WithSelector(s selector.Selector) CallOption { } } +// WithSelectOptions sets the options to pass to the selector for this call +func WithSelectOptions(sops ...selector.SelectOption) CallOption { + return func(o *CallOptions) { + o.SelectOptions = sops + } +} + func WithMessageContentType(ct string) MessageOption { return func(o *MessageOptions) { o.ContentType = ct diff --git a/client/rpc_client.go b/client/rpc_client.go index 7325ca50..2a3f9dd2 100644 --- a/client/rpc_client.go +++ b/client/rpc_client.go @@ -104,7 +104,7 @@ func (r *rpcClient) lookupRoute(req Request, opts CallOptions) (*router.Route, e } // select the route to use for the request - if route, err := opts.Selector.Select(routes); err == selector.ErrNoneAvailable { + if route, err := opts.Selector.Select(routes, opts.SelectOptions...); err == selector.ErrNoneAvailable { return nil, errors.InternalServerError("go.micro.client", "service %s: %s", req.Service(), err.Error()) } else if err != nil { return nil, errors.InternalServerError("go.micro.client", "error getting next %s node: %s", req.Service(), err.Error())