mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-24 10:07:04 +02:00
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 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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user