mirror of
https://github.com/aykhans/dodo.git
synced 2025-04-20 19:13:06 +00:00
🔨 Refactor pointers in the requests package
This commit is contained in:
parent
1ec4254468
commit
60335f7726
@ -80,7 +80,7 @@ func getClientDoFunc(
|
|||||||
}
|
}
|
||||||
return getSharedClientDoFunc(client, timeout)
|
return getSharedClientDoFunc(client, timeout)
|
||||||
} else if activeProxyClientsCount == 1 {
|
} else if activeProxyClientsCount == 1 {
|
||||||
client := &activeProxyClients[0]
|
client := activeProxyClients[0]
|
||||||
return getSharedClientDoFunc(client, timeout)
|
return getSharedClientDoFunc(client, timeout)
|
||||||
}
|
}
|
||||||
return getSharedRandomClientDoFunc(
|
return getSharedRandomClientDoFunc(
|
||||||
@ -112,8 +112,8 @@ func getActiveProxyClients(
|
|||||||
timeout time.Duration,
|
timeout time.Duration,
|
||||||
dodosCount int,
|
dodosCount int,
|
||||||
URL *url.URL,
|
URL *url.URL,
|
||||||
) []fasthttp.HostClient {
|
) []*fasthttp.HostClient {
|
||||||
activeProxyClientsArray := make([][]fasthttp.HostClient, dodosCount)
|
activeProxyClientsArray := make([][]*fasthttp.HostClient, dodosCount)
|
||||||
proxiesCount := len(proxies)
|
proxiesCount := len(proxies)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -169,7 +169,7 @@ func findActiveProxyClients(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
proxies []config.Proxy,
|
proxies []config.Proxy,
|
||||||
timeout time.Duration,
|
timeout time.Duration,
|
||||||
activeProxyClients *[]fasthttp.HostClient,
|
activeProxyClients *[]*fasthttp.HostClient,
|
||||||
increase chan<- int64,
|
increase chan<- int64,
|
||||||
URL *url.URL,
|
URL *url.URL,
|
||||||
wg *sync.WaitGroup,
|
wg *sync.WaitGroup,
|
||||||
@ -226,7 +226,7 @@ func findActiveProxyClients(
|
|||||||
if response.StatusCode() == 200 {
|
if response.StatusCode() == 200 {
|
||||||
*activeProxyClients = append(
|
*activeProxyClients = append(
|
||||||
*activeProxyClients,
|
*activeProxyClients,
|
||||||
fasthttp.HostClient{
|
&fasthttp.HostClient{
|
||||||
IsTLS: isTLS,
|
IsTLS: isTLS,
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
Dial: dialFunc,
|
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.
|
// getSharedRandomClientDoFunc is equivalent to getSharedClientDoFunc but uses a random client from the provided slice.
|
||||||
func getSharedRandomClientDoFunc(
|
func getSharedRandomClientDoFunc(
|
||||||
clients []fasthttp.HostClient,
|
clients []*fasthttp.HostClient,
|
||||||
clientsCount int,
|
clientsCount int,
|
||||||
timeout time.Duration,
|
timeout time.Duration,
|
||||||
) ClientDoFunc {
|
) ClientDoFunc {
|
||||||
return func(ctx context.Context, request *fasthttp.Request) (*fasthttp.Response, error) {
|
return func(ctx context.Context, request *fasthttp.Request) (*fasthttp.Response, error) {
|
||||||
client := &clients[rand.Intn(clientsCount)]
|
client := clients[rand.Intn(clientsCount)]
|
||||||
defer client.CloseIdleConnections()
|
defer client.CloseIdleConnections()
|
||||||
response := fasthttp.AcquireResponse()
|
response := fasthttp.AcquireResponse()
|
||||||
ch := make(chan error)
|
ch := make(chan error)
|
||||||
|
@ -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
|
// Print prints the responses in a tabular format, including information such as
|
||||||
// response count, minimum time, maximum time, and average time.
|
// response count, minimum time, maximum time, and average time.
|
||||||
func (respones *Responses) Print() {
|
func (respones Responses) Print() {
|
||||||
var (
|
var (
|
||||||
totalMinDuration time.Duration = (*respones)[0].Time
|
totalMinDuration time.Duration = respones[0].Time
|
||||||
totalMaxDuration time.Duration = (*respones)[0].Time
|
totalMaxDuration time.Duration = respones[0].Time
|
||||||
totalDuration time.Duration
|
totalDuration time.Duration
|
||||||
totalCount int = len(*respones)
|
totalCount int = len(respones)
|
||||||
)
|
)
|
||||||
mergedResponses := make(map[string][]time.Duration)
|
mergedResponses := make(map[string][]time.Duration)
|
||||||
|
|
||||||
for _, response := range *respones {
|
for _, response := range respones {
|
||||||
if response.Time < totalMinDuration {
|
if response.Time < totalMinDuration {
|
||||||
totalMinDuration = response.Time
|
totalMinDuration = response.Time
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user