From 60335f772694ea0f67cc1da99fc6cd505fe89a73 Mon Sep 17 00:00:00 2001 From: Aykhan Shahsuvarov Date: Tue, 10 Sep 2024 04:03:32 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Refactor=20pointers=20in=20the?= =?UTF-8?q?=20requests=20package?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requests/client.go | 14 +++++++------- requests/response.go | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/requests/client.go b/requests/client.go index d608bc1..65816f8 100644 --- a/requests/client.go +++ b/requests/client.go @@ -80,7 +80,7 @@ func getClientDoFunc( } return getSharedClientDoFunc(client, timeout) } else if activeProxyClientsCount == 1 { - client := &activeProxyClients[0] + client := activeProxyClients[0] return getSharedClientDoFunc(client, timeout) } return getSharedRandomClientDoFunc( @@ -112,8 +112,8 @@ func getActiveProxyClients( timeout time.Duration, dodosCount int, URL *url.URL, -) []fasthttp.HostClient { - activeProxyClientsArray := make([][]fasthttp.HostClient, dodosCount) +) []*fasthttp.HostClient { + activeProxyClientsArray := make([][]*fasthttp.HostClient, dodosCount) proxiesCount := len(proxies) var ( @@ -169,7 +169,7 @@ func findActiveProxyClients( ctx context.Context, proxies []config.Proxy, timeout time.Duration, - activeProxyClients *[]fasthttp.HostClient, + activeProxyClients *[]*fasthttp.HostClient, increase chan<- int64, URL *url.URL, wg *sync.WaitGroup, @@ -226,7 +226,7 @@ func findActiveProxyClients( if response.StatusCode() == 200 { *activeProxyClients = append( *activeProxyClients, - fasthttp.HostClient{ + &fasthttp.HostClient{ IsTLS: isTLS, Addr: addr, Dial: dialFunc, @@ -296,12 +296,12 @@ func getDialFunc(proxy *config.Proxy, timeout time.Duration) (fasthttp.DialFunc, // getSharedRandomClientDoFunc is equivalent to getSharedClientDoFunc but uses a random client from the provided slice. func getSharedRandomClientDoFunc( - clients []fasthttp.HostClient, + clients []*fasthttp.HostClient, clientsCount int, timeout time.Duration, ) ClientDoFunc { return func(ctx context.Context, request *fasthttp.Request) (*fasthttp.Response, error) { - client := &clients[rand.Intn(clientsCount)] + client := clients[rand.Intn(clientsCount)] defer client.CloseIdleConnections() response := fasthttp.AcquireResponse() ch := make(chan error) diff --git a/requests/response.go b/requests/response.go index 39f3c74..70a103a 100644 --- a/requests/response.go +++ b/requests/response.go @@ -23,16 +23,16 @@ type ClientDoFunc func(ctx context.Context, request *fasthttp.Request) (*fasthtt // Print prints the responses in a tabular format, including information such as // response count, minimum time, maximum time, and average time. -func (respones *Responses) Print() { +func (respones Responses) Print() { var ( - totalMinDuration time.Duration = (*respones)[0].Time - totalMaxDuration time.Duration = (*respones)[0].Time + totalMinDuration time.Duration = respones[0].Time + totalMaxDuration time.Duration = respones[0].Time totalDuration time.Duration - totalCount int = len(*respones) + totalCount int = len(respones) ) mergedResponses := make(map[string][]time.Duration) - for _, response := range *respones { + for _, response := range respones { if response.Time < totalMinDuration { totalMinDuration = response.Time }