remove comment
This commit is contained in:
parent
670ed74a13
commit
6070e235eb
@ -3,55 +3,6 @@ The Selector package provides a way to algorithmically filter and return
|
|||||||
nodes required by the client or any other system. Selector's implemented
|
nodes required by the client or any other system. Selector's implemented
|
||||||
by Micro build on the registry but it's of optional use. One could
|
by Micro build on the registry but it's of optional use. One could
|
||||||
provide a static Selector that has a fixed pool.
|
provide a static Selector that has a fixed pool.
|
||||||
|
|
||||||
func (r *randomSelector) Select(service string, opts ...SelectOption) (Next, error) {
|
|
||||||
var sopts SelectOptions
|
|
||||||
for _, opt := range opts {
|
|
||||||
opt(&sopts)
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the service
|
|
||||||
services, err := r.so.Registry.GetService(service)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// apply the filters
|
|
||||||
for _, filter := range sopts.Filters {
|
|
||||||
services = filter(services)
|
|
||||||
}
|
|
||||||
|
|
||||||
// if there's nothing left, return
|
|
||||||
if len(services) == 0 {
|
|
||||||
return nil, ErrNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
var nodes []*registry.Node
|
|
||||||
|
|
||||||
for _, service := range services {
|
|
||||||
for _, node := range service.Nodes {
|
|
||||||
nodes = append(nodes, node)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(nodes) == 0 {
|
|
||||||
return nil, ErrNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
return func() (*registry.Node, error) {
|
|
||||||
i := rand.Int()
|
|
||||||
j := i % len(services)
|
|
||||||
|
|
||||||
if len(services[j].Nodes) == 0 {
|
|
||||||
return nil, ErrNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
k := i % len(services[j].Nodes)
|
|
||||||
return services[j].Nodes[k], nil
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package selector
|
package selector
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user