🎨 auto formatted

This commit is contained in:
Aykhan Shahsuvarov 2024-09-03 02:09:00 +04:00
parent c2ce8e587b
commit 75ada96d35

View File

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