Compare commits

..

No commits in common. "fa55de0cf24278bc67ff3dab403eec6ff278270b" and "e3cbe1e9b47af34522cb3ba6050a9c3134c80082" have entirely different histories.

10 changed files with 55 additions and 232 deletions

View File

@ -1,6 +1,6 @@
<h1 align="center">Dodo is a simple and easy-to-use HTTP benchmarking tool.</h1>
<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>
## Installation
@ -33,7 +33,7 @@ Follow the steps below to build dodo:
3. **Build the project:**
```sh
go build -ldflags "-s -w" -o dodo
go build -o dodo
```
This will generate an executable named `dodo` in the project directory.
@ -58,9 +58,8 @@ You can find an example config structure in the [config.json](https://github.com
{
"method": "GET",
"url": "https://example.com",
"no_proxy_check": false,
"timeout": 2000,
"dodos_count": 10,
"timeout": 10000,
"dodos_count": 50,
"request_count": 1000,
"params": {},
"headers": {},
@ -78,7 +77,7 @@ You can find an example config structure in the [config.json](https://github.com
]
}
```
Send 1000 GET requests to https://example.com with 10 parallel dodos (threads) and a timeout of 2000 milliseconds:
Send 1000 GET requests to https://example.com with 5 parallel dodos (threads) and a timeout of 10000 milliseconds:
```sh
dodo -c /path/config.json
@ -102,18 +101,17 @@ docker run --rm -v ./path/config.json:/dodo/config.json -i aykhans/dodo -u https
## CLI and JSON Config Parameters
If the Headers, Params, Cookies and Body fields have multiple values, each request will choose a random value from the list.
| Parameter | JSON config file | CLI Flag | CLI Short Flag | Type | Description | Default |
| --------------------- | ---------------- | --------------- | -------------- | -------------------------------- | ------------------------------------------------------------------- | ----------- |
| Config file | - | --config-file | -c | String | Path to the JSON config file | - |
| Yes | - | --yes | -y | Boolean | Answer yes to all questions | false |
| URL | url | --url | -u | String | URL to send the request to | - |
| Method | method | --method | -m | String | HTTP method | GET |
| Request count | request_count | --request-count | -r | Integer | Total number of requests to send | 1000 |
| Dodos count (Threads) | dodos_count | --dodos-count | -d | Integer | Number of dodos (threads) to send requests in parallel | 1 |
| Timeout | timeout | --timeout | -t | Integer | Timeout for canceling each request (milliseconds) | 10000 |
| No Proxy Check | no_proxy_check | --no-proxy-check| - | Boolean | Disable proxy check | false |
| Params | params | - | - | Key-Value {String: [String]} | Request parameters | - |
| Headers | headers | - | - | Key-Value {String: [String]} | Request headers | - |
| Cookies | cookies | - | - | Key-Value {String: [String]} | Request cookies | - |
| Body | body | - | - | [String] | Request body | - |
| Proxy | proxies | - | - | List[Key-Value {string: string}] | List of proxies (will check active proxies before sending requests) | - |
| Parameter | JSON config file | CLI Flag | CLI Short Flag | Type | Description | Default |
| ----------- | ----------- | ----------- | ----------- | ----------- | ----------- | ----------- |
| Config file | - | --config-file | -c | String | Path to the JSON config file | - |
| Yes | - | --yes | -y | Boolean | Answer yes to all questions | false |
| URL | url | --url | -u | String | URL to send the request to | - |
| Method | method | --method | -m | String | HTTP method | GET |
| Request count | request_count | --request-count | -r | Integer | Total number of requests to send | 1000 |
| Dodos count (Threads) | dodos_count | --dodos-count | -d | Integer | Number of dodos (threads) to send requests in parallel | 1 |
| Timeout | timeout | --timeout | -t | Integer | Timeout for canceling each request (milliseconds) | 10000 |
| Params | params | - | - | Key-Value {String: [String]} | Request parameters | - |
| Headers | headers | - | - | Key-Value {String: [String]} | Request headers | - |
| Cookies | cookies | - | - | Key-Value {String: [String]} | Request cookies | - |
| Body | body | - | - | [String] | Request body | - |
| Proxy | proxies | - | - | List[Key-Value {string: string}] | List of proxies (will check active proxies before sending requests) | - |

BIN
assets/dodo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 KiB

View File

@ -1,7 +1,6 @@
{
"method": "GET",
"url": "https://example.com",
"no_proxy_check": true,
"timeout": 10000,
"dodos_count": 50,
"request_count": 1000,

View File

@ -11,7 +11,7 @@ import (
)
const (
VERSION string = "0.5.2"
VERSION string = "0.5.1"
DefaultUserAgent string = "Dodo/" + VERSION
ProxyCheckURL string = "https://www.google.com"
DefaultMethod string = "GET"
@ -21,6 +21,10 @@ const (
MaxDodosCountForProxies uint = 20 // Max dodos count for proxy check
)
type IConfig interface {
MergeConfigs(newConfig IConfig) IConfig
}
type RequestConfig struct {
Method string
URL *url.URL
@ -33,7 +37,6 @@ type RequestConfig struct {
Proxies []Proxy
Body []string
Yes bool
NoProxyCheck bool
}
func (config *RequestConfig) Print() {
@ -44,12 +47,6 @@ func (config *RequestConfig) Print() {
{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.AppendRow(table.Row{"Method", config.Method})
t.AppendSeparator()
@ -59,18 +56,16 @@ func (config *RequestConfig) Print() {
t.AppendSeparator()
t.AppendRow(table.Row{"Dodos", config.DodosCount})
t.AppendSeparator()
t.AppendRow(table.Row{"Requests", config.RequestCount})
t.AppendRow(table.Row{"Request", config.RequestCount})
t.AppendSeparator()
t.AppendRow(table.Row{"Params", utils.MarshalJSON(config.Params, 3)})
t.AppendSeparator()
t.AppendRow(table.Row{"Headers", utils.MarshalJSON(newHeaders, 3)})
t.AppendRow(table.Row{"Headers", utils.MarshalJSON(config.Headers, 3)})
t.AppendSeparator()
t.AppendRow(table.Row{"Cookies", utils.MarshalJSON(config.Cookies, 3)})
t.AppendSeparator()
t.AppendRow(table.Row{"Proxies Count", len(config.Proxies)})
t.AppendSeparator()
t.AppendRow(table.Row{"Proxy Check", !config.NoProxyCheck})
t.AppendSeparator()
t.AppendRow(table.Row{"Body", utils.MarshalJSON(config.Body, 3)})
t.Render()
@ -92,32 +87,11 @@ func (config *RequestConfig) GetMaxConns(minConns uint) uint {
}
type Config struct {
Method string `json:"method" validate:"http_method"` // custom validations: http_method
URL string `json:"url" validate:"http_url,required"`
Timeout uint32 `json:"timeout" validate:"gte=1,lte=100000"`
DodosCount uint `json:"dodos_count" validate:"gte=1"`
RequestCount uint `json:"request_count" validation_name:"request-count" validate:"gte=1"`
NoProxyCheck utils.Option[bool] `json:"no_proxy_check"`
}
func NewConfig(
method string,
timeout uint32,
dodosCount uint,
requestCount uint,
noProxyCheck utils.Option[bool],
) *Config {
if noProxyCheck == nil {
noProxyCheck = utils.NewNoneOption[bool]()
}
return &Config{
Method: method,
Timeout: timeout,
DodosCount: dodosCount,
RequestCount: requestCount,
NoProxyCheck: noProxyCheck,
}
Method string `json:"method" validate:"http_method"` // custom validations: http_method
URL string `json:"url" validate:"http_url,required"`
Timeout uint32 `json:"timeout" validate:"gte=1,lte=100000"`
DodosCount uint `json:"dodos_count" validate:"gte=1"`
RequestCount uint `json:"request_count" validation_name:"request-count" validate:"gte=1"`
}
func (config *Config) MergeConfigs(newConfig *Config) {
@ -136,9 +110,6 @@ func (config *Config) MergeConfigs(newConfig *Config) {
if newConfig.RequestCount != 0 {
config.RequestCount = newConfig.RequestCount
}
if !newConfig.NoProxyCheck.IsNone() {
config.NoProxyCheck = newConfig.NoProxyCheck
}
}
func (config *Config) SetDefaults() {
@ -154,9 +125,6 @@ func (config *Config) SetDefaults() {
if config.RequestCount == 0 {
config.RequestCount = DefaultRequestCount
}
if config.NoProxyCheck.IsNone() {
config.NoProxyCheck = utils.NewOption(false)
}
}
type Proxy struct {
@ -166,7 +134,7 @@ type Proxy struct {
}
type JSONConfig struct {
*Config
Config
Params map[string][]string `json:"params"`
Headers map[string][]string `json:"headers"`
Cookies map[string][]string `json:"cookies"`
@ -174,21 +142,8 @@ type JSONConfig struct {
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) {
config.Config.MergeConfigs(newConfig.Config)
config.Config.MergeConfigs(&newConfig.Config)
if len(newConfig.Params) != 0 {
config.Params = newConfig.Params
}
@ -207,23 +162,13 @@ func (config *JSONConfig) MergeConfigs(newConfig *JSONConfig) {
}
type CLIConfig struct {
*Config
Config
Yes bool `json:"yes" validate:"omitempty"`
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) {
config.Config.MergeConfigs(newConfig.Config)
config.Config.MergeConfigs(&newConfig.Config)
if newConfig.ConfigFile != "" {
config.ConfigFile = newConfig.ConfigFile
}

13
main.go
View File

@ -21,10 +21,8 @@ import (
func main() {
validator := validation.NewValidator()
conf := config.NewConfig("", 0, 0, 0, nil)
jsonConf := config.NewJSONConfig(
config.NewConfig("", 0, 0, 0, nil), nil, nil, nil, nil, nil,
)
conf := config.Config{}
jsonConf := config.JSONConfig{}
cliConf, err := readers.CLIConfigReader()
if err != nil || cliConf == nil {
@ -53,11 +51,11 @@ func main() {
),
)
}
jsonConf = jsonConfNew
conf.MergeConfigs(jsonConf.Config)
jsonConf = *jsonConfNew
conf.MergeConfigs(&jsonConf.Config)
}
conf.MergeConfigs(cliConf.Config)
conf.MergeConfigs(&cliConf.Config)
conf.SetDefaults()
if err := validator.Struct(conf); err != nil {
utils.PrintErrAndExit(
@ -83,7 +81,6 @@ func main() {
Proxies: jsonConf.Proxies,
Body: jsonConf.Body,
Yes: cliConf.Yes,
NoProxyCheck: conf.NoProxyCheck.ValueOrPanic(),
}
requestConf.Print()
if !cliConf.Yes {

View File

@ -13,11 +13,10 @@ import (
func CLIConfigReader() (*config.CLIConfig, error) {
var (
returnNil = false
cliConfig = config.NewCLIConfig(config.NewConfig("", 0, 0, 0, nil), false, "")
cliConfig = &config.CLIConfig{}
dodosCount uint
requestCount uint
timeout uint32
noProxyCheck bool
rootCmd = &cobra.Command{
Use: "dodo [flags]",
Example: ` Simple usage only with URL:
@ -27,7 +26,17 @@ func CLIConfigReader() (*config.CLIConfig, error) {
dodo -c /path/to/config/file/config.json
Usage with all flags:
dodo -c /path/to/config/file/config.json -u https://example.com -m POST -d 10 -r 1000 -t 2000 --no-proxy-check -y`,
dodo -c /path/to/config/file/config.json -u https://example.com -m POST -d 10 -r 1000 -t 2000`,
Short: `
`,
Run: func(cmd *cobra.Command, args []string) {},
SilenceErrors: true,
SilenceUsage: true,
@ -42,7 +51,6 @@ func CLIConfigReader() (*config.CLIConfig, error) {
rootCmd.Flags().UintVarP(&dodosCount, "dodos-count", "d", config.DefaultDodosCount, "Number of dodos(threads)")
rootCmd.Flags().UintVarP(&requestCount, "request-count", "r", config.DefaultRequestCount, "Number of total requests")
rootCmd.Flags().Uint32VarP(&timeout, "timeout", "t", config.DefaultTimeout, "Timeout for each request in milliseconds")
rootCmd.Flags().BoolVar(&noProxyCheck, "no-proxy-check", false, "Do not check for proxies")
if err := rootCmd.Execute(); err != nil {
utils.PrintErr(err)
rootCmd.Println(rootCmd.UsageString())
@ -60,8 +68,6 @@ func CLIConfigReader() (*config.CLIConfig, error) {
cliConfig.RequestCount = requestCount
case "timeout":
cliConfig.Timeout = timeout
case "no-proxy-check":
cliConfig.NoProxyCheck = utils.NewOption(noProxyCheck)
}
})
if returnNil {

View File

@ -5,7 +5,7 @@ import (
"os"
"github.com/aykhans/dodo/config"
customerrors "github.com/aykhans/dodo/custom_errors"
"github.com/aykhans/dodo/custom_errors"
)
func JSONConfigReader(filePath string) (*config.JSONConfig, error) {
@ -13,10 +13,7 @@ func JSONConfigReader(filePath string) (*config.JSONConfig, error) {
if err != nil {
return nil, customerrors.OSErrorFormater(err)
}
jsonConf := config.NewJSONConfig(
config.NewConfig("", 0, 0, 0, nil),
nil, nil, nil, nil, nil,
)
jsonConf := &config.JSONConfig{}
err = json.Unmarshal(data, &jsonConf)
if err != nil {

View File

@ -26,42 +26,11 @@ func getClients(
dodosCount uint,
maxConns uint,
yes bool,
noProxyCheck bool,
URL *url.URL,
) []*fasthttp.HostClient {
isTLS := URL.Scheme == "https"
if proxiesLen := len(proxies); proxiesLen > 0 {
// If noProxyCheck is true, we will return the clients without checking the proxies.
if noProxyCheck {
clients := make([]*fasthttp.HostClient, 0, proxiesLen)
addr := URL.Host
if isTLS && URL.Port() == "" {
addr += ":443"
}
for _, proxy := range proxies {
dialFunc, err := getDialFunc(&proxy, timeout)
if err != nil {
continue
}
clients = append(clients, &fasthttp.HostClient{
MaxConns: int(maxConns),
IsTLS: isTLS,
Addr: addr,
Dial: dialFunc,
MaxIdleConnDuration: timeout,
MaxConnDuration: timeout,
WriteTimeout: timeout,
ReadTimeout: timeout,
},
)
}
return clients
}
// Else, we will check the proxies and return the active ones.
if len(proxies) > 0 {
activeProxyClients := getActiveProxyClients(
ctx, proxies, timeout, dodosCount, maxConns, URL,
)

View File

@ -38,7 +38,6 @@ func Run(ctx context.Context, requestConfig *config.RequestConfig) (Responses, e
requestConfig.GetValidDodosCountForProxies(),
requestConfig.GetMaxConns(fasthttp.DefaultMaxConnsPerHost),
requestConfig.Yes,
requestConfig.NoProxyCheck,
requestConfig.URL,
)
if clients == nil {

View File

@ -1,87 +0,0 @@
package utils
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}
}