Add service random
This commit is contained in:
parent
29ee9e2753
commit
a2c862dd21
@ -48,7 +48,15 @@ func (r *randomSelector) Select(service string, opts ...SelectOption) (SelectNex
|
|||||||
}
|
}
|
||||||
|
|
||||||
return func() (*Node, error) {
|
return func() (*Node, error) {
|
||||||
return nodes[rand.Int()%len(nodes)], nil
|
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
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user