Skip to content

Commit 90404d5

Browse files
committed
feat: add feature to provide external counters
1 parent d59fe2f commit 90404d5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

client.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ func (i *IPMux) Client() *http.Client {
3434
return i.clients[i.counter.Load()%length]
3535
}
3636

37+
// ClientWithCounter returns one of the clients that is associated with one of the IPs given in New.
38+
// the function is safe to use without error handling of the constructor. it returns http.DefaultClient when there are no available clients.
39+
func (i *IPMux) ClientWithCounter(counter uint64) *http.Client {
40+
length := uint64(len(i.clients))
41+
if length == 0 {
42+
return http.DefaultClient
43+
}
44+
45+
return i.clients[counter%length]
46+
}
47+
3748
// Clients returns a list of all clients created for the list of ips given in New.
3849
// the function is safe to use without error handling of the constructor. it returns a list containing ob client (http.DefaultClient) when there are no available clients.
3950
func (i *IPMux) Clients() []*http.Client {

0 commit comments

Comments
 (0)