Fix some issues with initialisation
This commit is contained in:
parent
9ecbf0d71b
commit
897115ed31
@ -238,6 +238,7 @@ func (c *cmd) Before(ctx *cli.Context) error {
|
||||
|
||||
serverOpts = append(serverOpts, server.Broker(*c.opts.Broker))
|
||||
clientOpts = append(clientOpts, client.Broker(*c.opts.Broker))
|
||||
|
||||
}
|
||||
|
||||
// Set the registry
|
||||
@ -251,6 +252,9 @@ func (c *cmd) Before(ctx *cli.Context) error {
|
||||
|
||||
serverOpts = append(serverOpts, server.Registry(*c.opts.Registry))
|
||||
clientOpts = append(clientOpts, client.Registry(*c.opts.Registry))
|
||||
|
||||
(*c.opts.Selector).Init(selector.Registry(*c.opts.Registry))
|
||||
clientOpts = append(clientOpts, client.Selector(*c.opts.Selector))
|
||||
}
|
||||
|
||||
// Set the selector
|
||||
|
@ -28,6 +28,17 @@ func init() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
}
|
||||
|
||||
func (n *dcSelector) Init(opts ...selector.Option) error {
|
||||
for _, o := range opts {
|
||||
o(&n.opts)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *dcSelector) Options() selector.Options {
|
||||
return n.opts
|
||||
}
|
||||
|
||||
func (n *dcSelector) Select(service string, opts ...selector.SelectOption) (selector.Next, error) {
|
||||
services, err := n.opts.Registry.GetService(service)
|
||||
if err != nil {
|
||||
|
@ -22,6 +22,17 @@ type firstNodeSelector struct {
|
||||
opts selector.Options
|
||||
}
|
||||
|
||||
func (n *firstNodeSelector) Init(opts ...selector.Option) error {
|
||||
for _, o := range opts {
|
||||
o(&n.opts)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *firstNodeSelector) Options() selector.Options {
|
||||
return n.opts
|
||||
}
|
||||
|
||||
func (n *firstNodeSelector) Select(service string, opts ...selector.SelectOption) (selector.Next, error) {
|
||||
services, err := n.opts.Registry.GetService(service)
|
||||
if err != nil {
|
||||
|
@ -56,6 +56,17 @@ func (r *blackListSelector) run() {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *blackListSelector) Init(opts ...selector.Option) error {
|
||||
for _, o := range opts {
|
||||
o(&r.so)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *blackListSelector) Options() selector.Options {
|
||||
return r.so
|
||||
}
|
||||
|
||||
func (r *blackListSelector) Select(service string, opts ...selector.SelectOption) (selector.Next, error) {
|
||||
var sopts selector.SelectOptions
|
||||
for _, opt := range opts {
|
||||
|
@ -15,6 +15,17 @@ func init() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
}
|
||||
|
||||
func (r *randomSelector) Init(opts ...Option) error {
|
||||
for _, o := range opts {
|
||||
o(&r.so)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *randomSelector) Options() Options {
|
||||
return r.so
|
||||
}
|
||||
|
||||
func (r *randomSelector) Select(service string, opts ...SelectOption) (Next, error) {
|
||||
var sopts SelectOptions
|
||||
for _, opt := range opts {
|
||||
|
@ -16,6 +16,17 @@ func init() {
|
||||
cmd.DefaultSelectors["roundrobin"] = NewSelector
|
||||
}
|
||||
|
||||
func (r *roundRobinSelector) Init(opts ...selector.Option) error {
|
||||
for _, o := range opts {
|
||||
o(&r.so)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *roundRobinSelector) Options() selector.Options {
|
||||
return r.so
|
||||
}
|
||||
|
||||
func (r *roundRobinSelector) Select(service string, opts ...selector.SelectOption) (selector.Next, error) {
|
||||
var sopts selector.SelectOptions
|
||||
for _, opt := range opts {
|
||||
|
@ -64,6 +64,8 @@ import (
|
||||
// and mark their status. This allows host pools and other things
|
||||
// to be built using various algorithms.
|
||||
type Selector interface {
|
||||
Init(opts ...Option) error
|
||||
Options() Options
|
||||
// Select returns a function which should return the next node
|
||||
Select(service string, opts ...SelectOption) (Next, error)
|
||||
// Mark sets the success/error against a node
|
||||
|
Loading…
x
Reference in New Issue
Block a user