mirror of
https://github.com/aykhans/dodo.git
synced 2025-07-02 00:16:20 +00:00
🔨 Restructure entire project logic
- Moved readers to the config package - Added an option to read remote config files - Moved the validation package to the config package and removed the validator dependency - Moved the customerrors package to the config package - Replaced fatih/color with jedib0t/go-pretty/v6/text - Removed proxy check functionality - Added param, header, cookie, body, and proxy flags to the CLI - Allowed multiple values for the same key in params, headers, and cookies
This commit is contained in:
@ -7,48 +7,33 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/aykhans/dodo/config"
|
||||
customerrors "github.com/aykhans/dodo/custom_errors"
|
||||
"github.com/aykhans/dodo/types"
|
||||
"github.com/aykhans/dodo/utils"
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
// Run executes the main logic for processing requests based on the provided configuration.
|
||||
// It first checks for an internet connection with a timeout context. If no connection is found,
|
||||
// it returns an error. Then, it initializes clients based on the request configuration and
|
||||
// releases the dodos. If the context is canceled and no responses are collected, it returns an interrupt error.
|
||||
// It initializes clients based on the request configuration and releases the dodos.
|
||||
// If the context is canceled and no responses are collected, it returns an interrupt error.
|
||||
//
|
||||
// Parameters:
|
||||
// - ctx: The context for managing request lifecycle and cancellation.
|
||||
// - requestConfig: The configuration for the request, including timeout, proxies, and other settings.
|
||||
//
|
||||
// Returns:
|
||||
// - Responses: A collection of responses from the executed requests.
|
||||
// - error: An error if the operation fails, such as no internet connection or an interrupt.
|
||||
func Run(ctx context.Context, requestConfig *config.RequestConfig) (Responses, error) {
|
||||
checkConnectionCtx, checkConnectionCtxCancel := context.WithTimeout(ctx, 8*time.Second)
|
||||
if !checkConnection(checkConnectionCtx) {
|
||||
checkConnectionCtxCancel()
|
||||
return nil, customerrors.ErrNoInternet
|
||||
}
|
||||
checkConnectionCtxCancel()
|
||||
|
||||
clients := getClients(
|
||||
ctx,
|
||||
requestConfig.Timeout,
|
||||
requestConfig.Proxies,
|
||||
requestConfig.GetValidDodosCountForProxies(),
|
||||
requestConfig.GetMaxConns(fasthttp.DefaultMaxConnsPerHost),
|
||||
requestConfig.Yes,
|
||||
requestConfig.NoProxyCheck,
|
||||
requestConfig.URL,
|
||||
)
|
||||
if clients == nil {
|
||||
return nil, customerrors.ErrInterrupt
|
||||
return nil, types.ErrInterrupt
|
||||
}
|
||||
|
||||
responses := releaseDodos(ctx, requestConfig, clients)
|
||||
if ctx.Err() != nil && len(responses) == 0 {
|
||||
return nil, customerrors.ErrInterrupt
|
||||
return nil, types.ErrInterrupt
|
||||
}
|
||||
|
||||
return responses, nil
|
||||
@ -139,7 +124,7 @@ func sendRequest(
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if err == customerrors.ErrInterrupt {
|
||||
if err == types.ErrInterrupt {
|
||||
return
|
||||
}
|
||||
*responseData = append(*responseData, &Response{
|
||||
|
Reference in New Issue
Block a user