🔨 Refactor pointers in the requests package

This commit is contained in:
Aykhan Shahsuvarov 2024-09-10 04:03:32 +04:00
parent 1ec4254468
commit 60335f7726
2 changed files with 12 additions and 12 deletions

View File

@ -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)

View File

@ -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
}