Skip to content

Commit

Permalink
add/remove BalancingClient to be more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
treethought committed Mar 10, 2022
1 parent 624b4e0 commit cdb8cba
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions lbclient.go
Expand Up @@ -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,
Expand All @@ -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])
}
}
Expand Down

0 comments on commit cdb8cba

Please sign in to comment.