From fbc7acde95b695b92b9ad974ba28e5b7fe54730c Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Fri, 22 Sep 2017 10:14:31 +0900 Subject: [PATCH] client: permute endpoints manually (for Go 1.9>) To keep backward compatibility, use old algorithm of rand.Rand.Perm. Reference: https://github.com/golang/go/commit/caae0917bff12751019cb4240e99874fa692e770#diff-d4a72c5ba8515eae95a093e0aec62635. Signed-off-by: Gyu-Ho Lee --- client/client.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/client/client.go b/client/client.go index 3c8948252..e68745056 100644 --- a/client/client.go +++ b/client/client.go @@ -670,8 +670,15 @@ func (r *redirectedHTTPAction) HTTPRequest(ep url.URL) *http.Request { } func shuffleEndpoints(r *rand.Rand, eps []url.URL) []url.URL { - p := r.Perm(len(eps)) - neps := make([]url.URL, len(eps)) + // copied from Go 1.9<= rand.Rand.Perm + n := len(eps) + p := make([]int, n) + for i := 0; i < n; i++ { + j := r.Intn(i + 1) + p[i] = p[j] + p[j] = i + } + neps := make([]url.URL, n) for i, k := range p { neps[i] = eps[k] }