Moved to google.golang.org/genproto/googleapis/api/annotations
Fixes #52
This commit is contained in:
32
vendor/github.com/go-kit/kit/sd/lb/random.go
generated
vendored
Normal file
32
vendor/github.com/go-kit/kit/sd/lb/random.go
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
package lb
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
"github.com/go-kit/kit/sd"
|
||||
)
|
||||
|
||||
// NewRandom returns a load balancer that selects services randomly.
|
||||
func NewRandom(s sd.Subscriber, seed int64) Balancer {
|
||||
return &random{
|
||||
s: s,
|
||||
r: rand.New(rand.NewSource(seed)),
|
||||
}
|
||||
}
|
||||
|
||||
type random struct {
|
||||
s sd.Subscriber
|
||||
r *rand.Rand
|
||||
}
|
||||
|
||||
func (r *random) Endpoint() (endpoint.Endpoint, error) {
|
||||
endpoints, err := r.s.Endpoints()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(endpoints) <= 0 {
|
||||
return nil, ErrNoEndpoints
|
||||
}
|
||||
return endpoints[r.r.Intn(len(endpoints))], nil
|
||||
}
|
||||
Reference in New Issue
Block a user