mirror of
https://github.com/aykhans/dodo.git
synced 2025-07-01 07:57:48 +00:00
Compare commits
1 Commits
v0.5.3
...
6e4a676d43
Author | SHA1 | Date | |
---|---|---|---|
6e4a676d43 |
@ -1,6 +1,6 @@
|
|||||||
<h1 align="center">Dodo is a simple and easy-to-use HTTP benchmarking tool.</h1>
|
<h1 align="center">Dodo is a simple and easy-to-use HTTP benchmarking tool.</h1>
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img width="30%" height="30%" src="https://ftp.aykhans.me/web/client/pubshares/hB6VSdCnBCr8gFPeiMuCji/browse?path=%2Fdodo.png">
|
<img width="30%" height="30%" src="https://raw.githubusercontent.com/aykhans/dodo/main/assets/dodo.png">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
@ -49,7 +49,7 @@ dodo -u https://example.com -m GET -d 10 -r 1000 -t 2000
|
|||||||
```
|
```
|
||||||
With Docker:
|
With Docker:
|
||||||
```sh
|
```sh
|
||||||
docker run --rm -i aykhans/dodo -u https://example.com -m GET -d 10 -r 1000 -t 2000
|
docker run --rm aykhans/dodo -u https://example.com -m GET -d 10 -r 1000 -t 2000
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2. JSON config file
|
### 2. JSON config file
|
||||||
@ -85,7 +85,7 @@ dodo -c /path/config.json
|
|||||||
```
|
```
|
||||||
With Docker:
|
With Docker:
|
||||||
```sh
|
```sh
|
||||||
docker run --rm -i -v ./path/config.json:/dodo/config.json aykhans/dodo
|
docker run --rm -v ./path/config.json:/dodo/config.json -i aykhans/dodo
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3. Both (CLI & JSON)
|
### 3. Both (CLI & JSON)
|
||||||
@ -96,7 +96,7 @@ dodo -c /path/config.json -u https://example.com -m GET -d 10 -r 1000 -t 2000
|
|||||||
```
|
```
|
||||||
With Docker:
|
With Docker:
|
||||||
```sh
|
```sh
|
||||||
docker run --rm -i -v ./path/config.json:/dodo/config.json aykhans/dodo -u https://example.com -m GET -d 10 -r 1000 -t 2000
|
docker run --rm -v ./path/config.json:/dodo/config.json -i aykhans/dodo -u https://example.com -m GET -d 10 -r 1000 -t 2000
|
||||||
```
|
```
|
||||||
|
|
||||||
## CLI and JSON Config Parameters
|
## CLI and JSON Config Parameters
|
||||||
|
BIN
assets/dodo.png
Normal file
BIN
assets/dodo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 230 KiB |
@ -19,4 +19,4 @@
|
|||||||
"url": "http://example.com:8080"
|
"url": "http://example.com:8080"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -6,13 +6,12 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/aykhans/dodo/types"
|
|
||||||
"github.com/aykhans/dodo/utils"
|
"github.com/aykhans/dodo/utils"
|
||||||
"github.com/jedib0t/go-pretty/v6/table"
|
"github.com/jedib0t/go-pretty/v6/table"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION string = "0.5.3"
|
VERSION string = "0.5.2"
|
||||||
DefaultUserAgent string = "Dodo/" + VERSION
|
DefaultUserAgent string = "Dodo/" + VERSION
|
||||||
ProxyCheckURL string = "https://www.google.com"
|
ProxyCheckURL string = "https://www.google.com"
|
||||||
DefaultMethod string = "GET"
|
DefaultMethod string = "GET"
|
||||||
@ -22,6 +21,10 @@ const (
|
|||||||
MaxDodosCountForProxies uint = 20 // Max dodos count for proxy check
|
MaxDodosCountForProxies uint = 20 // Max dodos count for proxy check
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type IConfig interface {
|
||||||
|
MergeConfigs(newConfig IConfig) IConfig
|
||||||
|
}
|
||||||
|
|
||||||
type RequestConfig struct {
|
type RequestConfig struct {
|
||||||
Method string
|
Method string
|
||||||
URL *url.URL
|
URL *url.URL
|
||||||
@ -45,12 +48,6 @@ func (config *RequestConfig) Print() {
|
|||||||
{Number: 2, WidthMax: 50},
|
{Number: 2, WidthMax: 50},
|
||||||
})
|
})
|
||||||
|
|
||||||
newHeaders := make(map[string][]string)
|
|
||||||
newHeaders["User-Agent"] = []string{DefaultUserAgent}
|
|
||||||
for k, v := range config.Headers {
|
|
||||||
newHeaders[k] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
t.AppendHeader(table.Row{"Request Configuration"})
|
t.AppendHeader(table.Row{"Request Configuration"})
|
||||||
t.AppendRow(table.Row{"Method", config.Method})
|
t.AppendRow(table.Row{"Method", config.Method})
|
||||||
t.AppendSeparator()
|
t.AppendSeparator()
|
||||||
@ -60,11 +57,11 @@ func (config *RequestConfig) Print() {
|
|||||||
t.AppendSeparator()
|
t.AppendSeparator()
|
||||||
t.AppendRow(table.Row{"Dodos", config.DodosCount})
|
t.AppendRow(table.Row{"Dodos", config.DodosCount})
|
||||||
t.AppendSeparator()
|
t.AppendSeparator()
|
||||||
t.AppendRow(table.Row{"Requests", config.RequestCount})
|
t.AppendRow(table.Row{"Request", config.RequestCount})
|
||||||
t.AppendSeparator()
|
t.AppendSeparator()
|
||||||
t.AppendRow(table.Row{"Params", utils.MarshalJSON(config.Params, 3)})
|
t.AppendRow(table.Row{"Params", utils.MarshalJSON(config.Params, 3)})
|
||||||
t.AppendSeparator()
|
t.AppendSeparator()
|
||||||
t.AppendRow(table.Row{"Headers", utils.MarshalJSON(newHeaders, 3)})
|
t.AppendRow(table.Row{"Headers", utils.MarshalJSON(config.Headers, 3)})
|
||||||
t.AppendSeparator()
|
t.AppendSeparator()
|
||||||
t.AppendRow(table.Row{"Cookies", utils.MarshalJSON(config.Cookies, 3)})
|
t.AppendRow(table.Row{"Cookies", utils.MarshalJSON(config.Cookies, 3)})
|
||||||
t.AppendSeparator()
|
t.AppendSeparator()
|
||||||
@ -93,32 +90,12 @@ func (config *RequestConfig) GetMaxConns(minConns uint) uint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Method string `json:"method" validate:"http_method"` // custom validations: http_method
|
Method string `json:"method" validate:"http_method"` // custom validations: http_method
|
||||||
URL string `json:"url" validate:"http_url,required"`
|
URL string `json:"url" validate:"http_url,required"`
|
||||||
Timeout uint32 `json:"timeout" validate:"gte=1,lte=100000"`
|
Timeout uint32 `json:"timeout" validate:"gte=1,lte=100000"`
|
||||||
DodosCount uint `json:"dodos_count" validate:"gte=1"`
|
DodosCount uint `json:"dodos_count" validate:"gte=1"`
|
||||||
RequestCount uint `json:"request_count" validation_name:"request-count" validate:"gte=1"`
|
RequestCount uint `json:"request_count" validation_name:"request-count" validate:"gte=1"`
|
||||||
NoProxyCheck Option[bool] `json:"no_proxy_check"`
|
NoProxyCheck utils.IOption[bool] `json:"no_proxy_check"`
|
||||||
}
|
|
||||||
|
|
||||||
func NewConfig(
|
|
||||||
method string,
|
|
||||||
timeout uint32,
|
|
||||||
dodosCount uint,
|
|
||||||
requestCount uint,
|
|
||||||
noProxyCheck Option[bool],
|
|
||||||
) *Config {
|
|
||||||
if noProxyCheck == nil {
|
|
||||||
noProxyCheck = NewNoneOption[bool]()
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Config{
|
|
||||||
Method: method,
|
|
||||||
Timeout: timeout,
|
|
||||||
DodosCount: dodosCount,
|
|
||||||
RequestCount: requestCount,
|
|
||||||
NoProxyCheck: noProxyCheck,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *Config) MergeConfigs(newConfig *Config) {
|
func (config *Config) MergeConfigs(newConfig *Config) {
|
||||||
@ -156,7 +133,7 @@ func (config *Config) SetDefaults() {
|
|||||||
config.RequestCount = DefaultRequestCount
|
config.RequestCount = DefaultRequestCount
|
||||||
}
|
}
|
||||||
if config.NoProxyCheck.IsNone() {
|
if config.NoProxyCheck.IsNone() {
|
||||||
config.NoProxyCheck = NewOption(false)
|
config.NoProxyCheck = utils.NewOption(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +144,7 @@ type Proxy struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type JSONConfig struct {
|
type JSONConfig struct {
|
||||||
*Config
|
Config
|
||||||
Params map[string][]string `json:"params"`
|
Params map[string][]string `json:"params"`
|
||||||
Headers map[string][]string `json:"headers"`
|
Headers map[string][]string `json:"headers"`
|
||||||
Cookies map[string][]string `json:"cookies"`
|
Cookies map[string][]string `json:"cookies"`
|
||||||
@ -175,21 +152,8 @@ type JSONConfig struct {
|
|||||||
Body []string `json:"body"`
|
Body []string `json:"body"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewJSONConfig(
|
|
||||||
config *Config,
|
|
||||||
params map[string][]string,
|
|
||||||
headers map[string][]string,
|
|
||||||
cookies map[string][]string,
|
|
||||||
proxies []Proxy,
|
|
||||||
body []string,
|
|
||||||
) *JSONConfig {
|
|
||||||
return &JSONConfig{
|
|
||||||
config, params, headers, cookies, proxies, body,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (config *JSONConfig) MergeConfigs(newConfig *JSONConfig) {
|
func (config *JSONConfig) MergeConfigs(newConfig *JSONConfig) {
|
||||||
config.Config.MergeConfigs(newConfig.Config)
|
config.Config.MergeConfigs(&newConfig.Config)
|
||||||
if len(newConfig.Params) != 0 {
|
if len(newConfig.Params) != 0 {
|
||||||
config.Params = newConfig.Params
|
config.Params = newConfig.Params
|
||||||
}
|
}
|
||||||
@ -208,23 +172,13 @@ func (config *JSONConfig) MergeConfigs(newConfig *JSONConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CLIConfig struct {
|
type CLIConfig struct {
|
||||||
*Config
|
Config
|
||||||
Yes bool `json:"yes" validate:"omitempty"`
|
Yes bool `json:"yes" validate:"omitempty"`
|
||||||
ConfigFile string `validation_name:"config-file" validate:"omitempty,filepath"`
|
ConfigFile string `validation_name:"config-file" validate:"omitempty,filepath"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCLIConfig(
|
|
||||||
config *Config,
|
|
||||||
yes bool,
|
|
||||||
configFile string,
|
|
||||||
) *CLIConfig {
|
|
||||||
return &CLIConfig{
|
|
||||||
config, yes, configFile,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (config *CLIConfig) MergeConfigs(newConfig *CLIConfig) {
|
func (config *CLIConfig) MergeConfigs(newConfig *CLIConfig) {
|
||||||
config.Config.MergeConfigs(newConfig.Config)
|
config.Config.MergeConfigs(&newConfig.Config)
|
||||||
if newConfig.ConfigFile != "" {
|
if newConfig.ConfigFile != "" {
|
||||||
config.ConfigFile = newConfig.ConfigFile
|
config.ConfigFile = newConfig.ConfigFile
|
||||||
}
|
}
|
||||||
|
14
go.mod
14
go.mod
@ -4,11 +4,11 @@ go 1.23.2
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/go-playground/validator/v10 v10.23.0
|
github.com/go-playground/validator/v10 v10.23.0
|
||||||
github.com/jedib0t/go-pretty/v6 v6.6.5
|
github.com/jedib0t/go-pretty/v6 v6.6.2
|
||||||
github.com/spf13/cobra v1.8.1
|
github.com/spf13/cobra v1.8.1
|
||||||
github.com/spf13/pflag v1.0.5
|
github.com/spf13/pflag v1.0.5
|
||||||
github.com/valyala/fasthttp v1.58.0
|
github.com/valyala/fasthttp v1.57.0
|
||||||
golang.org/x/net v0.32.0
|
golang.org/x/net v0.31.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@ -22,8 +22,8 @@ require (
|
|||||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||||
github.com/rivo/uniseg v0.4.7 // indirect
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||||
golang.org/x/crypto v0.31.0 // indirect
|
golang.org/x/crypto v0.29.0 // indirect
|
||||||
golang.org/x/sys v0.28.0 // indirect
|
golang.org/x/sys v0.27.0 // indirect
|
||||||
golang.org/x/term v0.27.0 // indirect
|
golang.org/x/term v0.26.0 // indirect
|
||||||
golang.org/x/text v0.21.0 // indirect
|
golang.org/x/text v0.20.0 // indirect
|
||||||
)
|
)
|
||||||
|
28
go.sum
28
go.sum
@ -15,8 +15,8 @@ github.com/go-playground/validator/v10 v10.23.0 h1:/PwmTwZhS0dPkav3cdK9kV1FsAmrL
|
|||||||
github.com/go-playground/validator/v10 v10.23.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
github.com/go-playground/validator/v10 v10.23.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||||
github.com/jedib0t/go-pretty/v6 v6.6.5 h1:9PgMJOVBedpgYLI56jQRJYqngxYAAzfEUua+3NgSqAo=
|
github.com/jedib0t/go-pretty/v6 v6.6.2 h1:27bLj3nRODzaiA7tPIxy9UVWHoPspFfME9XxgwiiNsM=
|
||||||
github.com/jedib0t/go-pretty/v6 v6.6.5/go.mod h1:Uq/HrbhuFty5WSVNfjpQQe47x16RwVGXIveNGEyGtHs=
|
github.com/jedib0t/go-pretty/v6 v6.6.2/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
|
||||||
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
|
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
|
||||||
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
|
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
|
||||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||||
@ -37,20 +37,20 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
|
|||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||||
github.com/valyala/fasthttp v1.58.0 h1:GGB2dWxSbEprU9j0iMJHgdKYJVDyjrOwF9RE59PbRuE=
|
github.com/valyala/fasthttp v1.57.0 h1:Xw8SjWGEP/+wAAgyy5XTvgrWlOD1+TxbbvNADYCm1Tg=
|
||||||
github.com/valyala/fasthttp v1.58.0/go.mod h1:SYXvHHaFp7QZHGKSHmoMipInhrI5StHrhDTYVEjK/Kw=
|
github.com/valyala/fasthttp v1.57.0/go.mod h1:h6ZBaPRlzpZ6O3H5t2gEk1Qi33+TmLvfwgLLp0t9CpE=
|
||||||
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
|
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
|
||||||
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
||||||
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
|
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
|
||||||
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
|
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
|
||||||
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
|
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
|
||||||
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
|
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
|
||||||
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
|
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
|
||||||
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
|
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
|
||||||
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
|
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
|
||||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
|
||||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
14
main.go
14
main.go
@ -21,10 +21,8 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
validator := validation.NewValidator()
|
validator := validation.NewValidator()
|
||||||
conf := config.NewConfig("", 0, 0, 0, nil)
|
conf := config.Config{}
|
||||||
jsonConf := config.NewJSONConfig(
|
jsonConf := config.JSONConfig{}
|
||||||
config.NewConfig("", 0, 0, 0, nil), nil, nil, nil, nil, nil,
|
|
||||||
)
|
|
||||||
|
|
||||||
cliConf, err := readers.CLIConfigReader()
|
cliConf, err := readers.CLIConfigReader()
|
||||||
if err != nil || cliConf == nil {
|
if err != nil || cliConf == nil {
|
||||||
@ -53,11 +51,11 @@ func main() {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
jsonConf = jsonConfNew
|
jsonConf = *jsonConfNew
|
||||||
conf.MergeConfigs(jsonConf.Config)
|
conf.MergeConfigs(&jsonConf.Config)
|
||||||
}
|
}
|
||||||
|
|
||||||
conf.MergeConfigs(cliConf.Config)
|
conf.MergeConfigs(&cliConf.Config)
|
||||||
conf.SetDefaults()
|
conf.SetDefaults()
|
||||||
if err := validator.Struct(conf); err != nil {
|
if err := validator.Struct(conf); err != nil {
|
||||||
utils.PrintErrAndExit(
|
utils.PrintErrAndExit(
|
||||||
@ -83,7 +81,7 @@ func main() {
|
|||||||
Proxies: jsonConf.Proxies,
|
Proxies: jsonConf.Proxies,
|
||||||
Body: jsonConf.Body,
|
Body: jsonConf.Body,
|
||||||
Yes: cliConf.Yes,
|
Yes: cliConf.Yes,
|
||||||
NoProxyCheck: conf.NoProxyCheck.ValueOrPanic(),
|
NoProxyCheck: *conf.NoProxyCheck.ValueOrPanic(),
|
||||||
}
|
}
|
||||||
requestConf.Print()
|
requestConf.Print()
|
||||||
if !cliConf.Yes {
|
if !cliConf.Yes {
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
|
|
||||||
"github.com/aykhans/dodo/config"
|
"github.com/aykhans/dodo/config"
|
||||||
"github.com/aykhans/dodo/custom_errors"
|
"github.com/aykhans/dodo/custom_errors"
|
||||||
. "github.com/aykhans/dodo/types"
|
|
||||||
"github.com/aykhans/dodo/utils"
|
"github.com/aykhans/dodo/utils"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
@ -13,8 +12,12 @@ import (
|
|||||||
|
|
||||||
func CLIConfigReader() (*config.CLIConfig, error) {
|
func CLIConfigReader() (*config.CLIConfig, error) {
|
||||||
var (
|
var (
|
||||||
returnNil = false
|
returnNil = false
|
||||||
cliConfig = config.NewCLIConfig(config.NewConfig("", 0, 0, 0, nil), false, "")
|
cliConfig = &config.CLIConfig{
|
||||||
|
Config: config.Config{
|
||||||
|
NoProxyCheck: utils.NewNoneOption[bool](),
|
||||||
|
},
|
||||||
|
}
|
||||||
dodosCount uint
|
dodosCount uint
|
||||||
requestCount uint
|
requestCount uint
|
||||||
timeout uint32
|
timeout uint32
|
||||||
@ -62,7 +65,7 @@ func CLIConfigReader() (*config.CLIConfig, error) {
|
|||||||
case "timeout":
|
case "timeout":
|
||||||
cliConfig.Timeout = timeout
|
cliConfig.Timeout = timeout
|
||||||
case "no-proxy-check":
|
case "no-proxy-check":
|
||||||
cliConfig.NoProxyCheck = NewOption(noProxyCheck)
|
cliConfig.NoProxyCheck = utils.NewOption(noProxyCheck)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if returnNil {
|
if returnNil {
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/aykhans/dodo/config"
|
"github.com/aykhans/dodo/config"
|
||||||
customerrors "github.com/aykhans/dodo/custom_errors"
|
customerrors "github.com/aykhans/dodo/custom_errors"
|
||||||
|
"github.com/aykhans/dodo/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func JSONConfigReader(filePath string) (*config.JSONConfig, error) {
|
func JSONConfigReader(filePath string) (*config.JSONConfig, error) {
|
||||||
@ -13,10 +14,11 @@ func JSONConfigReader(filePath string) (*config.JSONConfig, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, customerrors.OSErrorFormater(err)
|
return nil, customerrors.OSErrorFormater(err)
|
||||||
}
|
}
|
||||||
jsonConf := config.NewJSONConfig(
|
jsonConf := &config.JSONConfig{
|
||||||
config.NewConfig("", 0, 0, 0, nil),
|
Config: config.Config{
|
||||||
nil, nil, nil, nil, nil,
|
NoProxyCheck: utils.NewNoneOption[bool](),
|
||||||
)
|
},
|
||||||
|
}
|
||||||
err = json.Unmarshal(data, &jsonConf)
|
err = json.Unmarshal(data, &jsonConf)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,106 +1,85 @@
|
|||||||
package requests
|
package requests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/aykhans/dodo/types"
|
"github.com/aykhans/dodo/utils"
|
||||||
"github.com/jedib0t/go-pretty/v6/table"
|
"github.com/jedib0t/go-pretty/v6/table"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
Response string
|
StatusCode int
|
||||||
Time time.Duration
|
Error error
|
||||||
|
Time time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
type Responses []*Response
|
type Responses []*Response
|
||||||
|
|
||||||
// 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, average time, and latency percentiles.
|
// response count, minimum time, maximum time, and average time.
|
||||||
func (respones Responses) Print() {
|
func (respones Responses) Print() {
|
||||||
total := struct {
|
var (
|
||||||
Count int
|
totalMinDuration time.Duration = respones[0].Time
|
||||||
Min time.Duration
|
totalMaxDuration time.Duration = respones[0].Time
|
||||||
Max time.Duration
|
totalDuration time.Duration
|
||||||
Sum time.Duration
|
totalCount int = len(respones)
|
||||||
P90 time.Duration
|
)
|
||||||
P95 time.Duration
|
mergedResponses := make(map[string][]time.Duration)
|
||||||
P99 time.Duration
|
|
||||||
}{
|
|
||||||
Count: len(respones),
|
|
||||||
Min: respones[0].Time,
|
|
||||||
Max: respones[0].Time,
|
|
||||||
}
|
|
||||||
mergedResponses := make(map[string]Durations)
|
|
||||||
var allDurations Durations
|
|
||||||
|
|
||||||
for _, response := range respones {
|
for _, response := range respones {
|
||||||
if response.Time < total.Min {
|
if response.Time < totalMinDuration {
|
||||||
total.Min = response.Time
|
totalMinDuration = response.Time
|
||||||
}
|
}
|
||||||
if response.Time > total.Max {
|
if response.Time > totalMaxDuration {
|
||||||
total.Max = response.Time
|
totalMaxDuration = response.Time
|
||||||
}
|
}
|
||||||
total.Sum += response.Time
|
totalDuration += response.Time
|
||||||
|
|
||||||
mergedResponses[response.Response] = append(
|
if response.Error != nil {
|
||||||
mergedResponses[response.Response],
|
mergedResponses[response.Error.Error()] = append(
|
||||||
response.Time,
|
mergedResponses[response.Error.Error()],
|
||||||
)
|
response.Time,
|
||||||
allDurations = append(allDurations, response.Time)
|
)
|
||||||
|
} else {
|
||||||
|
mergedResponses[fmt.Sprintf("%d", response.StatusCode)] = append(
|
||||||
|
mergedResponses[fmt.Sprintf("%d", response.StatusCode)],
|
||||||
|
response.Time,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
allDurations.Sort()
|
|
||||||
allDurationsLenAsFloat := float64(len(allDurations) - 1)
|
|
||||||
total.P90 = allDurations[int(0.90*allDurationsLenAsFloat)]
|
|
||||||
total.P95 = allDurations[int(0.95*allDurationsLenAsFloat)]
|
|
||||||
total.P99 = allDurations[int(0.99*allDurationsLenAsFloat)]
|
|
||||||
|
|
||||||
t := table.NewWriter()
|
t := table.NewWriter()
|
||||||
t.SetOutputMirror(os.Stdout)
|
t.SetOutputMirror(os.Stdout)
|
||||||
t.SetStyle(table.StyleLight)
|
t.SetStyle(table.StyleLight)
|
||||||
t.SetColumnConfigs([]table.ColumnConfig{
|
t.SetColumnConfigs([]table.ColumnConfig{
|
||||||
{Number: 1, WidthMax: 40},
|
{Number: 1, WidthMax: 80},
|
||||||
})
|
})
|
||||||
|
|
||||||
t.AppendHeader(table.Row{
|
t.AppendHeader(table.Row{
|
||||||
"Response",
|
"Response",
|
||||||
"Count",
|
"Count",
|
||||||
"Min Time",
|
"Min Time",
|
||||||
"Max Time",
|
"Max Time",
|
||||||
"Average Time",
|
"Average Time",
|
||||||
"P90",
|
|
||||||
"P95",
|
|
||||||
"P99",
|
|
||||||
})
|
})
|
||||||
|
|
||||||
for key, durations := range mergedResponses {
|
for key, durations := range mergedResponses {
|
||||||
durations.Sort()
|
|
||||||
durationsLen := len(durations)
|
|
||||||
durationsLenAsFloat := float64(durationsLen - 1)
|
|
||||||
|
|
||||||
t.AppendRow(table.Row{
|
t.AppendRow(table.Row{
|
||||||
key,
|
key,
|
||||||
durationsLen,
|
len(durations),
|
||||||
durations.First(),
|
utils.MinDuration(durations...),
|
||||||
durations.Last(),
|
utils.MaxDuration(durations...),
|
||||||
durations.Avg(),
|
utils.AvgDuration(durations...),
|
||||||
durations[int(0.90*durationsLenAsFloat)],
|
|
||||||
durations[int(0.95*durationsLenAsFloat)],
|
|
||||||
durations[int(0.99*durationsLenAsFloat)],
|
|
||||||
})
|
})
|
||||||
t.AppendSeparator()
|
t.AppendSeparator()
|
||||||
}
|
}
|
||||||
|
t.AppendRow(table.Row{
|
||||||
if len(mergedResponses) > 1 {
|
"Total",
|
||||||
t.AppendRow(table.Row{
|
totalCount,
|
||||||
"Total",
|
totalMinDuration,
|
||||||
total.Count,
|
totalMaxDuration,
|
||||||
total.Min,
|
totalDuration / time.Duration(totalCount),
|
||||||
total.Max,
|
})
|
||||||
total.Sum / time.Duration(total.Count), // Average
|
|
||||||
total.P90,
|
|
||||||
total.P95,
|
|
||||||
total.P99,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
t.Render()
|
t.Render()
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package requests
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strconv"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -143,16 +142,18 @@ func sendRequest(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
*responseData = append(*responseData, &Response{
|
*responseData = append(*responseData, &Response{
|
||||||
Response: err.Error(),
|
StatusCode: 0,
|
||||||
Time: completedTime,
|
Error: err,
|
||||||
|
Time: completedTime,
|
||||||
})
|
})
|
||||||
increase <- 1
|
increase <- 1
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
*responseData = append(*responseData, &Response{
|
*responseData = append(*responseData, &Response{
|
||||||
Response: strconv.Itoa(response.StatusCode()),
|
StatusCode: response.StatusCode(),
|
||||||
Time: completedTime,
|
Error: nil,
|
||||||
|
Time: completedTime,
|
||||||
})
|
})
|
||||||
increase <- 1
|
increase <- 1
|
||||||
}()
|
}()
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
package types
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sort"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Durations []time.Duration
|
|
||||||
|
|
||||||
func (d Durations) Sort(ascending ...bool) {
|
|
||||||
// If ascending is provided and is false, sort in descending order
|
|
||||||
if len(ascending) > 0 && ascending[0] == false {
|
|
||||||
sort.Slice(d, func(i, j int) bool {
|
|
||||||
return d[i] > d[j]
|
|
||||||
})
|
|
||||||
} else { // Otherwise, sort in ascending order
|
|
||||||
sort.Slice(d, func(i, j int) bool {
|
|
||||||
return d[i] < d[j]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Durations) First() *time.Duration {
|
|
||||||
return &d[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Durations) Last() *time.Duration {
|
|
||||||
return &d[len(d)-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Durations) Sum() time.Duration {
|
|
||||||
sum := time.Duration(0)
|
|
||||||
for _, duration := range d {
|
|
||||||
sum += duration
|
|
||||||
}
|
|
||||||
return sum
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Durations) Avg() time.Duration {
|
|
||||||
return d.Sum() / time.Duration(len(d))
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
package types
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
type NonNilT interface {
|
|
||||||
~int | ~float64 | ~string | ~bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type Option[T NonNilT] interface {
|
|
||||||
IsNone() bool
|
|
||||||
ValueOrErr() (T, error)
|
|
||||||
ValueOr(def T) T
|
|
||||||
ValueOrPanic() T
|
|
||||||
UnmarshalJSON(data []byte) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't call this struct directly, use NewOption[T] or NewNoneOption[T] instead.
|
|
||||||
type option[T NonNilT] struct {
|
|
||||||
// value holds the actual value of the Option if it is not None.
|
|
||||||
value T
|
|
||||||
// none indicates whether the Option is None (i.e., has no value).
|
|
||||||
none bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *option[T]) IsNone() bool {
|
|
||||||
return o.none
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the Option is None, it will return zero value of the type and an error.
|
|
||||||
func (o *option[T]) ValueOrErr() (T, error) {
|
|
||||||
if o.IsNone() {
|
|
||||||
return o.value, errors.New("Option is None")
|
|
||||||
}
|
|
||||||
return o.value, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the Option is None, it will return the default value.
|
|
||||||
func (o *option[T]) ValueOr(def T) T {
|
|
||||||
if o.IsNone() {
|
|
||||||
return def
|
|
||||||
}
|
|
||||||
return o.value
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the Option is None, it will panic.
|
|
||||||
func (o *option[T]) ValueOrPanic() T {
|
|
||||||
if o.IsNone() {
|
|
||||||
panic("Option is None")
|
|
||||||
}
|
|
||||||
return o.value
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *option[T]) SetValue(value T) {
|
|
||||||
o.value = value
|
|
||||||
o.none = false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *option[T]) SetNone() {
|
|
||||||
var zeroValue T
|
|
||||||
o.value = zeroValue
|
|
||||||
o.none = true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *option[T]) UnmarshalJSON(data []byte) error {
|
|
||||||
if string(data) == "null" || len(data) == 0 {
|
|
||||||
o.SetNone()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := json.Unmarshal(data, &o.value); err != nil {
|
|
||||||
o.SetNone()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
o.none = false
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewOption[T NonNilT](value T) *option[T] {
|
|
||||||
return &option[T]{value: value}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewNoneOption[T NonNilT]() *option[T] {
|
|
||||||
return &option[T]{none: true}
|
|
||||||
}
|
|
31
utils/time.go
Normal file
31
utils/time.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
func MinDuration(durations ...time.Duration) time.Duration {
|
||||||
|
min := durations[0]
|
||||||
|
for _, d := range durations {
|
||||||
|
if d < min {
|
||||||
|
min = d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return min
|
||||||
|
}
|
||||||
|
|
||||||
|
func MaxDuration(durations ...time.Duration) time.Duration {
|
||||||
|
max := durations[0]
|
||||||
|
for _, d := range durations {
|
||||||
|
if d > max {
|
||||||
|
max = d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return max
|
||||||
|
}
|
||||||
|
|
||||||
|
func AvgDuration(durations ...time.Duration) time.Duration {
|
||||||
|
total := time.Duration(0)
|
||||||
|
for _, d := range durations {
|
||||||
|
total += d
|
||||||
|
}
|
||||||
|
return total / time.Duration(len(durations))
|
||||||
|
}
|
71
utils/types.go
Normal file
71
utils/types.go
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type NonNilConcrete interface {
|
||||||
|
~int | ~float64 | ~string | ~bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type IOption[T NonNilConcrete] interface {
|
||||||
|
IsNone() bool
|
||||||
|
ValueOrErr() (*T, error)
|
||||||
|
ValueOr(def *T) *T
|
||||||
|
ValueOrPanic() *T
|
||||||
|
UnmarshalJSON(data []byte) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't call this struct directly, use NewOption[T] or NewNoneOption[T] instead.
|
||||||
|
type option[T NonNilConcrete] struct {
|
||||||
|
// value holds the actual value of the Option if it is not None.
|
||||||
|
value T
|
||||||
|
// none indicates whether the Option is None (i.e., has no value).
|
||||||
|
none bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *option[T]) IsNone() bool {
|
||||||
|
return o.none
|
||||||
|
}
|
||||||
|
|
||||||
|
// The returned value can be nil, if the Option is None, it will return nil and an error.
|
||||||
|
func (o *option[T]) ValueOrErr() (*T, error) {
|
||||||
|
if o.IsNone() {
|
||||||
|
return nil, errors.New("Option is None")
|
||||||
|
}
|
||||||
|
return &o.value, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// The returned value can't be nil, if the Option is None, it will return the default value.
|
||||||
|
func (o *option[T]) ValueOr(def *T) *T {
|
||||||
|
if o.IsNone() {
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
return &o.value
|
||||||
|
}
|
||||||
|
|
||||||
|
// The returned value can't be nil, if the Option is None, it will panic.
|
||||||
|
func (o *option[T]) ValueOrPanic() *T {
|
||||||
|
if o.IsNone() {
|
||||||
|
panic("Option is None")
|
||||||
|
}
|
||||||
|
return &o.value
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *option[T]) UnmarshalJSON(data []byte) error {
|
||||||
|
if string(data) == "null" {
|
||||||
|
o.none = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
o.none = false
|
||||||
|
return json.Unmarshal(data, &o.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewOption[T NonNilConcrete](value T) *option[T] {
|
||||||
|
return &option[T]{value: value}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNoneOption[T NonNilConcrete]() *option[T] {
|
||||||
|
return &option[T]{none: true}
|
||||||
|
}
|
Reference in New Issue
Block a user