client: add select options (#1786)

This commit is contained in:
ben-toogood 2020-07-02 17:03:08 +01:00 committed by GitHub
parent 6898a65508
commit b021546c09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions

View File

@ -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())

View File

@ -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

View File

@ -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())