client: add select options (#1786)
This commit is contained in:
parent
6898a65508
commit
b021546c09
@ -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())
|
||||
|
@ -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
|
||||
|
@ -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())
|
||||
|
Loading…
x
Reference in New Issue
Block a user