From 75ada96d35509ef3728905a23e825cb74a64c173 Mon Sep 17 00:00:00 2001 From: Aykhan Shahsuvarov Date: Tue, 3 Sep 2024 02:09:00 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20auto=20formatted?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requests/requests.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/requests/requests.go b/requests/requests.go index d4ed843..46976b2 100644 --- a/requests/requests.go +++ b/requests/requests.go @@ -518,7 +518,7 @@ func getSharedRandomClientDoFunc( clientsCount int, timeout time.Duration, ) 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)] defer client.CloseIdleConnections() response := fasthttp.AcquireResponse() @@ -550,16 +550,17 @@ func getSharedRandomClientDoFunc( // The function internally creates a new response using fasthttp.AcquireResponse() and a channel to handle errors. // It then spawns a goroutine to execute the client.DoTimeout() method with the given request, response, and timeout. // The function uses a select statement to handle three cases: -// - If an error is received from the channel, it checks if the error is not nil. If it's not nil, it releases the response and returns nil and the error. -// Otherwise, it returns the response and nil. -// - If the timeout duration is reached, it releases the response and returns nil and a custom timeout error. -// - If the context is canceled, it returns nil and a custom interrupt error. +// - If an error is received from the channel, it checks if the error is not nil. If it's not nil, it releases the response and returns nil and the error. +// Otherwise, it returns the response and nil. +// - If the timeout duration is reached, it releases the response and returns nil and a custom timeout error. +// - If the context is canceled, it returns nil and a custom interrupt error. +// // The function ensures that idle connections are closed by calling client.CloseIdleConnections() using a defer statement. func getSharedClientDoFunc( client *fasthttp.HostClient, timeout time.Duration, ) ClientDoFunc { - return func (ctx context.Context, request *fasthttp.Request) (*fasthttp.Response, error) { + return func(ctx context.Context, request *fasthttp.Request) (*fasthttp.Response, error) { defer client.CloseIdleConnections() response := fasthttp.AcquireResponse() ch := make(chan error)