mirror of
https://github.com/aykhans/dodo.git
synced 2025-04-20 11:11:26 +00:00
Merge a468f663bfb536ec5feb8748611eaf1ae0119c8e into 565079fe970f9bdcff3dd0310556377f226da91c
This commit is contained in:
commit
2bd45e22a4
38
README.md
38
README.md
@ -33,7 +33,7 @@ Follow the steps below to build dodo:
|
|||||||
3. **Build the project:**
|
3. **Build the project:**
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
go build -o dodo
|
go build -ldflags "-s -w" -o dodo
|
||||||
```
|
```
|
||||||
|
|
||||||
This will generate an executable named `dodo` in the project directory.
|
This will generate an executable named `dodo` in the project directory.
|
||||||
@ -58,8 +58,9 @@ You can find an example config structure in the [config.json](https://github.com
|
|||||||
{
|
{
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"url": "https://example.com",
|
"url": "https://example.com",
|
||||||
"timeout": 10000,
|
"no_proxy_check": false,
|
||||||
"dodos_count": 50,
|
"timeout": 2000,
|
||||||
|
"dodos_count": 10,
|
||||||
"request_count": 1000,
|
"request_count": 1000,
|
||||||
"params": {},
|
"params": {},
|
||||||
"headers": {},
|
"headers": {},
|
||||||
@ -77,7 +78,7 @@ You can find an example config structure in the [config.json](https://github.com
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
Send 1000 GET requests to https://example.com with 5 parallel dodos (threads) and a timeout of 10000 milliseconds:
|
Send 1000 GET requests to https://example.com with 10 parallel dodos (threads) and a timeout of 2000 milliseconds:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
dodo -c /path/config.json
|
dodo -c /path/config.json
|
||||||
@ -101,17 +102,18 @@ docker run --rm -v ./path/config.json:/dodo/config.json -i aykhans/dodo -u https
|
|||||||
## CLI and JSON Config Parameters
|
## 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.
|
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 |
|
| Parameter | JSON config file | CLI Flag | CLI Short Flag | Type | Description | Default |
|
||||||
| ----------- | ----------- | ----------- | ----------- | ----------- | ----------- | ----------- |
|
| --------------------- | ---------------- | --------------- | -------------- | -------------------------------- | ------------------------------------------------------------------- | ----------- |
|
||||||
| Config file | - | --config-file | -c | String | Path to the JSON config file | - |
|
| Config file | - | --config-file | -c | String | Path to the JSON config file | - |
|
||||||
| Yes | - | --yes | -y | Boolean | Answer yes to all questions | false |
|
| Yes | - | --yes | -y | Boolean | Answer yes to all questions | false |
|
||||||
| URL | url | --url | -u | String | URL to send the request to | - |
|
| URL | url | --url | -u | String | URL to send the request to | - |
|
||||||
| Method | method | --method | -m | String | HTTP method | GET |
|
| Method | method | --method | -m | String | HTTP method | GET |
|
||||||
| Request count | request_count | --request-count | -r | Integer | Total number of requests to send | 1000 |
|
| 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 |
|
| 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 |
|
| Timeout | timeout | --timeout | -t | Integer | Timeout for canceling each request (milliseconds) | 10000 |
|
||||||
| Params | params | - | - | Key-Value {String: [String]} | Request parameters | - |
|
| No Proxy Check | no_proxy_check | --no-proxy-check| - | Boolean | Disable proxy check | false |
|
||||||
| Headers | headers | - | - | Key-Value {String: [String]} | Request headers | - |
|
| Params | params | - | - | Key-Value {String: [String]} | Request parameters | - |
|
||||||
| Cookies | cookies | - | - | Key-Value {String: [String]} | Request cookies | - |
|
| Headers | headers | - | - | Key-Value {String: [String]} | Request headers | - |
|
||||||
| Body | body | - | - | [String] | Request body | - |
|
| Cookies | cookies | - | - | Key-Value {String: [String]} | Request cookies | - |
|
||||||
| Proxy | proxies | - | - | List[Key-Value {string: string}] | List of proxies (will check active proxies before sending requests) | - |
|
| Body | body | - | - | [String] | Request body | - |
|
||||||
|
| Proxy | proxies | - | - | List[Key-Value {string: string}] | List of proxies (will check active proxies before sending requests) | - |
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"url": "https://example.com",
|
"url": "https://example.com",
|
||||||
|
"no_proxy_check": false,
|
||||||
"timeout": 10000,
|
"timeout": 10000,
|
||||||
"dodos_count": 50,
|
"dodos_count": 50,
|
||||||
"request_count": 1000,
|
"request_count": 1000,
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION string = "0.5.1"
|
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"
|
||||||
@ -37,6 +37,7 @@ type RequestConfig struct {
|
|||||||
Proxies []Proxy
|
Proxies []Proxy
|
||||||
Body []string
|
Body []string
|
||||||
Yes bool
|
Yes bool
|
||||||
|
NoProxyCheck bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *RequestConfig) Print() {
|
func (config *RequestConfig) Print() {
|
||||||
@ -66,6 +67,8 @@ func (config *RequestConfig) Print() {
|
|||||||
t.AppendSeparator()
|
t.AppendSeparator()
|
||||||
t.AppendRow(table.Row{"Proxies Count", len(config.Proxies)})
|
t.AppendRow(table.Row{"Proxies Count", len(config.Proxies)})
|
||||||
t.AppendSeparator()
|
t.AppendSeparator()
|
||||||
|
t.AppendRow(table.Row{"Proxy Check", !config.NoProxyCheck})
|
||||||
|
t.AppendSeparator()
|
||||||
t.AppendRow(table.Row{"Body", utils.MarshalJSON(config.Body, 3)})
|
t.AppendRow(table.Row{"Body", utils.MarshalJSON(config.Body, 3)})
|
||||||
|
|
||||||
t.Render()
|
t.Render()
|
||||||
@ -87,11 +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 utils.Option[bool] `json:"no_proxy_check"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *Config) MergeConfigs(newConfig *Config) {
|
func (config *Config) MergeConfigs(newConfig *Config) {
|
||||||
@ -110,6 +114,9 @@ func (config *Config) MergeConfigs(newConfig *Config) {
|
|||||||
if newConfig.RequestCount != 0 {
|
if newConfig.RequestCount != 0 {
|
||||||
config.RequestCount = newConfig.RequestCount
|
config.RequestCount = newConfig.RequestCount
|
||||||
}
|
}
|
||||||
|
if !newConfig.NoProxyCheck.IsNone() {
|
||||||
|
config.NoProxyCheck = newConfig.NoProxyCheck
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *Config) SetDefaults() {
|
func (config *Config) SetDefaults() {
|
||||||
@ -125,6 +132,9 @@ func (config *Config) SetDefaults() {
|
|||||||
if config.RequestCount == 0 {
|
if config.RequestCount == 0 {
|
||||||
config.RequestCount = DefaultRequestCount
|
config.RequestCount = DefaultRequestCount
|
||||||
}
|
}
|
||||||
|
if config.NoProxyCheck.IsNone() {
|
||||||
|
config.NoProxyCheck = utils.NewOption(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Proxy struct {
|
type Proxy struct {
|
||||||
|
1
main.go
1
main.go
@ -81,6 +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(),
|
||||||
}
|
}
|
||||||
requestConf.Print()
|
requestConf.Print()
|
||||||
if !cliConf.Yes {
|
if !cliConf.Yes {
|
||||||
|
@ -13,10 +13,15 @@ import (
|
|||||||
func CLIConfigReader() (*config.CLIConfig, error) {
|
func CLIConfigReader() (*config.CLIConfig, error) {
|
||||||
var (
|
var (
|
||||||
returnNil = false
|
returnNil = false
|
||||||
cliConfig = &config.CLIConfig{}
|
cliConfig = &config.CLIConfig{
|
||||||
|
Config: config.Config{
|
||||||
|
NoProxyCheck: utils.NewNoneOption[bool](),
|
||||||
|
},
|
||||||
|
}
|
||||||
dodosCount uint
|
dodosCount uint
|
||||||
requestCount uint
|
requestCount uint
|
||||||
timeout uint32
|
timeout uint32
|
||||||
|
noProxyCheck bool
|
||||||
rootCmd = &cobra.Command{
|
rootCmd = &cobra.Command{
|
||||||
Use: "dodo [flags]",
|
Use: "dodo [flags]",
|
||||||
Example: ` Simple usage only with URL:
|
Example: ` Simple usage only with URL:
|
||||||
@ -26,17 +31,7 @@ func CLIConfigReader() (*config.CLIConfig, error) {
|
|||||||
dodo -c /path/to/config/file/config.json
|
dodo -c /path/to/config/file/config.json
|
||||||
|
|
||||||
Usage with all flags:
|
Usage with all flags:
|
||||||
dodo -c /path/to/config/file/config.json -u https://example.com -m POST -d 10 -r 1000 -t 2000`,
|
dodo -c /path/to/config/file/config.json -u https://example.com -m POST -d 10 -r 1000 -t 2000 --no-proxy-check -y`,
|
||||||
Short: `
|
|
||||||
██████████ ███████ ██████████ ███████
|
|
||||||
░░███░░░░███ ███░░░░░███ ░░███░░░░███ ███░░░░░███
|
|
||||||
░███ ░░███ ███ ░░███ ░███ ░░███ ███ ░░███
|
|
||||||
░███ ░███░███ ░███ ░███ ░███░███ ░███
|
|
||||||
░███ ░███░███ ░███ ░███ ░███░███ ░███
|
|
||||||
░███ ███ ░░███ ███ ░███ ███ ░░███ ███
|
|
||||||
██████████ ░░░███████░ ██████████ ░░░███████░
|
|
||||||
░░░░░░░░░░ ░░░░░░░ ░░░░░░░░░░ ░░░░░░░
|
|
||||||
`,
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {},
|
Run: func(cmd *cobra.Command, args []string) {},
|
||||||
SilenceErrors: true,
|
SilenceErrors: true,
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
@ -51,6 +46,7 @@ func CLIConfigReader() (*config.CLIConfig, error) {
|
|||||||
rootCmd.Flags().UintVarP(&dodosCount, "dodos-count", "d", config.DefaultDodosCount, "Number of dodos(threads)")
|
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().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().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 {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
utils.PrintErr(err)
|
utils.PrintErr(err)
|
||||||
rootCmd.Println(rootCmd.UsageString())
|
rootCmd.Println(rootCmd.UsageString())
|
||||||
@ -68,6 +64,8 @@ func CLIConfigReader() (*config.CLIConfig, error) {
|
|||||||
cliConfig.RequestCount = requestCount
|
cliConfig.RequestCount = requestCount
|
||||||
case "timeout":
|
case "timeout":
|
||||||
cliConfig.Timeout = timeout
|
cliConfig.Timeout = timeout
|
||||||
|
case "no-proxy-check":
|
||||||
|
cliConfig.NoProxyCheck = utils.NewOption(noProxyCheck)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if returnNil {
|
if returnNil {
|
||||||
|
@ -5,7 +5,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/aykhans/dodo/config"
|
"github.com/aykhans/dodo/config"
|
||||||
"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,7 +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.JSONConfig{}
|
jsonConf := &config.JSONConfig{
|
||||||
|
Config: config.Config{
|
||||||
|
NoProxyCheck: utils.NewNoneOption[bool](),
|
||||||
|
},
|
||||||
|
}
|
||||||
err = json.Unmarshal(data, &jsonConf)
|
err = json.Unmarshal(data, &jsonConf)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -26,11 +26,42 @@ func getClients(
|
|||||||
dodosCount uint,
|
dodosCount uint,
|
||||||
maxConns uint,
|
maxConns uint,
|
||||||
yes bool,
|
yes bool,
|
||||||
|
noProxyCheck bool,
|
||||||
URL *url.URL,
|
URL *url.URL,
|
||||||
) []*fasthttp.HostClient {
|
) []*fasthttp.HostClient {
|
||||||
isTLS := URL.Scheme == "https"
|
isTLS := URL.Scheme == "https"
|
||||||
|
|
||||||
if len(proxies) > 0 {
|
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.
|
||||||
activeProxyClients := getActiveProxyClients(
|
activeProxyClients := getActiveProxyClients(
|
||||||
ctx, proxies, timeout, dodosCount, maxConns, URL,
|
ctx, proxies, timeout, dodosCount, maxConns, URL,
|
||||||
)
|
)
|
||||||
|
@ -38,6 +38,7 @@ func Run(ctx context.Context, requestConfig *config.RequestConfig) (Responses, e
|
|||||||
requestConfig.GetValidDodosCountForProxies(),
|
requestConfig.GetValidDodosCountForProxies(),
|
||||||
requestConfig.GetMaxConns(fasthttp.DefaultMaxConnsPerHost),
|
requestConfig.GetMaxConns(fasthttp.DefaultMaxConnsPerHost),
|
||||||
requestConfig.Yes,
|
requestConfig.Yes,
|
||||||
|
requestConfig.NoProxyCheck,
|
||||||
requestConfig.URL,
|
requestConfig.URL,
|
||||||
)
|
)
|
||||||
if clients == nil {
|
if clients == nil {
|
||||||
|
59
utils/types.go
Normal file
59
utils/types.go
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Don't call this struct directly, use NewOption[T] or NewNoneOption[T] instead.
|
||||||
|
type Option[T any] 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 any](value T) Option[T] {
|
||||||
|
return Option[T]{value: value}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNoneOption[T any]() Option[T] {
|
||||||
|
return Option[T]{none: true}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user