🔨 Refactor all requests package logic.

- Replace net/http with fasthttp in the requests package.
This commit is contained in:
2024-07-21 19:40:16 +04:00
parent 61ff1d5941
commit 670d07bda2
7 changed files with 491 additions and 337 deletions

47
main.go
View File

@@ -1,18 +1,18 @@
package main
import (
"net/url"
"os"
"strings"
"time"
"github.com/aykhans/dodo/config"
"github.com/aykhans/dodo/custom_errors"
customerrors "github.com/aykhans/dodo/custom_errors"
"github.com/aykhans/dodo/readers"
"github.com/aykhans/dodo/requests"
"github.com/aykhans/dodo/utils"
"github.com/aykhans/dodo/validation"
goValidator "github.com/go-playground/validator/v10"
"github.com/jedib0t/go-pretty/v6/table"
)
func main() {
@@ -61,9 +61,13 @@ func main() {
)
}
dodoConf := &config.DodoConfig{
parsedURL, err := url.Parse(conf.URL)
if err != nil {
utils.PrintErrAndExit(err)
}
dodoConf := &config.RequestConfig{
Method: conf.Method,
URL: conf.URL,
URL: parsedURL,
Timeout: time.Duration(conf.Timeout) * time.Millisecond,
DodosCount: conf.DodosCount,
RequestCount: conf.RequestCount,
@@ -73,39 +77,8 @@ func main() {
Proxies: jsonConf.Proxies,
Body: jsonConf.Body,
}
dodoConf.Print()
responses, err := requests.Run(dodoConf)
if err != nil {
utils.PrintErrAndExit(err)
}
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.SetStyle(table.StyleLight)
t.AppendHeader(table.Row{
"Response",
"Count",
"Min Time",
"Max Time",
"Average Time",
})
for _, mergedResponse := range responses.MergeDodoResponses() {
t.AppendRow(table.Row{
mergedResponse.Response,
mergedResponse.Count,
mergedResponse.MinTime,
mergedResponse.MaxTime,
mergedResponse.AvgTime,
})
t.AppendSeparator()
}
t.AppendFooter(table.Row{
"Total",
responses.Len(),
responses.MinTime(),
responses.MaxTime(),
responses.AvgTime(),
})
t.Render()
responses := requests.Run(dodoConf)
responses.Print()
}