Move to a selector package

This commit is contained in:
Asim
2015-12-09 19:23:16 +00:00
parent 91405e5993
commit eefb9c53d4
18 changed files with 304 additions and 188 deletions

View File

@@ -4,6 +4,7 @@ import (
"github.com/micro/go-micro/broker"
"github.com/micro/go-micro/codec"
"github.com/micro/go-micro/registry"
"github.com/micro/go-micro/selector"
"github.com/micro/go-micro/transport"
)
@@ -12,13 +13,13 @@ type options struct {
broker broker.Broker
codecs map[string]codec.NewCodec
registry registry.Registry
selector registry.Selector
selector selector.Selector
transport transport.Transport
wrappers []Wrapper
}
type callOptions struct {
selectOptions []registry.SelectOption
selectOptions []selector.SelectOption
}
type publishOptions struct{}
@@ -59,7 +60,7 @@ func Transport(t transport.Transport) Option {
}
// Select is used to select a node to route a request to
func Selector(s registry.Selector) Option {
func Selector(s selector.Selector) Option {
return func(o *options) {
o.selector = s
}
@@ -74,7 +75,7 @@ func Wrap(w Wrapper) Option {
// Call Options
func WithSelectOption(so registry.SelectOption) CallOption {
func WithSelectOption(so selector.SelectOption) CallOption {
return func(o *callOptions) {
o.selectOptions = append(o.selectOptions, so)
}

View File

@@ -10,6 +10,7 @@ import (
c "github.com/micro/go-micro/context"
"github.com/micro/go-micro/errors"
"github.com/micro/go-micro/registry"
"github.com/micro/go-micro/selector"
"github.com/micro/go-micro/transport"
"golang.org/x/net/context"
@@ -44,8 +45,8 @@ func newRpcClient(opt ...Option) Client {
}
if opts.selector == nil {
opts.selector = registry.NewRandomSelector(
registry.SelectorRegistry(opts.registry),
opts.selector = selector.NewSelector(
selector.Registry(opts.registry),
)
}
@@ -156,14 +157,14 @@ func (r *rpcClient) Call(ctx context.Context, request Request, response interfac
}
next, err := r.opts.selector.Select(request.Service(), copts.selectOptions...)
if err != nil && err == registry.ErrNotFound {
if err != nil && err == selector.ErrNotFound {
return errors.NotFound("go.micro.client", err.Error())
} else if err != nil {
return errors.InternalServerError("go.micro.client", err.Error())
}
node, err := next()
if err != nil && err == registry.ErrNotFound {
if err != nil && err == selector.ErrNotFound {
return errors.NotFound("go.micro.client", err.Error())
} else if err != nil {
return errors.InternalServerError("go.micro.client", err.Error())
@@ -190,14 +191,14 @@ func (r *rpcClient) Stream(ctx context.Context, request Request, responseChan in
}
next, err := r.opts.selector.Select(request.Service(), copts.selectOptions...)
if err != nil && err == registry.ErrNotFound {
if err != nil && err == selector.ErrNotFound {
return nil, errors.NotFound("go.micro.client", err.Error())
} else if err != nil {
return nil, errors.InternalServerError("go.micro.client", err.Error())
}
node, err := next()
if err != nil && err == registry.ErrNotFound {
if err != nil && err == selector.ErrNotFound {
return nil, errors.NotFound("go.micro.client", err.Error())
} else if err != nil {
return nil, errors.InternalServerError("go.micro.client", err.Error())