From 9d99accce2ab959162523b19771186ced220fa49 Mon Sep 17 00:00:00 2001 From: John Ku Date: Fri, 11 Dec 2015 13:48:02 -0800 Subject: [PATCH] Allow built in selectionHandlers to be reused outside of package --- client/pool.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/client/pool.go b/client/pool.go index a6e7243..9b94888 100644 --- a/client/pool.go +++ b/client/pool.go @@ -11,9 +11,7 @@ const ( ) var ( - ErrNotFound = errors.New("Server Not Found") - SelectWithRate = selectWithRate - SelectRandom = selectRandom + ErrNotFound = errors.New("Server Not Found") ) type PoolClient struct { @@ -24,7 +22,7 @@ type PoolClient struct { type SelectionHandler func(map[string]*PoolClient, string) string -func selectWithRate(pool map[string]*PoolClient, +func SelectWithRate(pool map[string]*PoolClient, last string) (addr string) { total := 0 for _, item := range pool { @@ -36,7 +34,7 @@ func selectWithRate(pool map[string]*PoolClient, return last } -func selectRandom(pool map[string]*PoolClient, +func SelectRandom(pool map[string]*PoolClient, last string) (addr string) { r := rand.Intn(len(pool)) i := 0