From cdb8cba4f176c7b9308e9e7d53b581311c5276ed Mon Sep 17 00:00:00 2001 From: Cam Sweeney Date: Thu, 10 Mar 2022 11:55:10 -0800 Subject: [PATCH] add/remove BalancingClient to be more flexible --- lbclient.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lbclient.go b/lbclient.go index 7dd4b9ab13..9e530d0fcd 100644 --- a/lbclient.go +++ b/lbclient.go @@ -94,7 +94,7 @@ func (cc *LBClient) init() { // AddClient adds a new HostClient to the balanced clients // returns the new total number of clients -func (cc *LBClient) AddClient(c *HostClient) int { +func (cc *LBClient) AddClient(c BalancingClient) int { cc.mu.Lock() cc.cs = append(cc.cs, &lbClient{ c: c, @@ -107,15 +107,10 @@ func (cc *LBClient) AddClient(c *HostClient) int { // RemoveClients removes clients using the provided callback // if rc returns true, the passed client will be removed // returns the new total number of clients -func (cc *LBClient) RemoveClients(rc func(*HostClient) bool) int { +func (cc *LBClient) RemoveClients(rc func(BalancingClient) bool) int { cc.mu.Lock() for idx, cs := range cc.cs { - // ignore non HostClient BalancingClients - hc, ok := cs.c.(*HostClient) - if !ok { - continue - } - if rc(hc) { + if rc(cs.c) { cc.cs = append(cc.cs[:idx], cc.cs[idx+1]) } }