mirror of
https://github.com/aykhans/dodo.git
synced 2025-07-01 07:57:48 +00:00
Compare commits
1 Commits
v0.5.2
...
159ab66b58
Author | SHA1 | Date | |
---|---|---|---|
159ab66b58 |
@ -1,4 +1,4 @@
|
||||
FROM golang:1.23.2-alpine AS builder
|
||||
FROM golang:1.22.6-alpine AS builder
|
||||
|
||||
WORKDIR /dodo
|
||||
|
||||
|
11
README.md
11
README.md
@ -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
|
||||
|
BIN
assets/dodo.png
Normal file
BIN
assets/dodo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 230 KiB |
@ -1,7 +1,7 @@
|
||||
{
|
||||
"method": "GET",
|
||||
"url": "https://example.com",
|
||||
"no_proxy_check": true,
|
||||
"no_proxy_check": false,
|
||||
"timeout": 10000,
|
||||
"dodos_count": 50,
|
||||
"request_count": 1000,
|
||||
|
@ -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
|
||||
@ -44,12 +48,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,11 +57,11 @@ 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()
|
||||
@ -100,26 +98,6 @@ type Config struct {
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
func (config *Config) MergeConfigs(newConfig *Config) {
|
||||
if newConfig.Method != "" {
|
||||
config.Method = newConfig.Method
|
||||
@ -166,7 +144,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 +152,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 +172,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
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@ -1,6 +1,6 @@
|
||||
module github.com/aykhans/dodo
|
||||
|
||||
go 1.23.2
|
||||
go 1.22.6
|
||||
|
||||
require (
|
||||
github.com/go-playground/validator/v10 v10.23.0
|
||||
|
14
main.go
14
main.go
@ -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,7 @@ func main() {
|
||||
Proxies: jsonConf.Proxies,
|
||||
Body: jsonConf.Body,
|
||||
Yes: cliConf.Yes,
|
||||
NoProxyCheck: conf.NoProxyCheck.ValueOrPanic(),
|
||||
NoProxyCheck: *conf.NoProxyCheck.ValueOrPanic(),
|
||||
}
|
||||
requestConf.Print()
|
||||
if !cliConf.Yes {
|
||||
|
@ -13,7 +13,11 @@ import (
|
||||
func CLIConfigReader() (*config.CLIConfig, error) {
|
||||
var (
|
||||
returnNil = false
|
||||
cliConfig = config.NewCLIConfig(config.NewConfig("", 0, 0, 0, nil), false, "")
|
||||
cliConfig = &config.CLIConfig{
|
||||
Config: config.Config{
|
||||
NoProxyCheck: utils.NewNoneOption[bool](),
|
||||
},
|
||||
}
|
||||
dodosCount uint
|
||||
requestCount uint
|
||||
timeout uint32
|
||||
@ -27,7 +31,7 @@ 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`,
|
||||
Run: func(cmd *cobra.Command, args []string) {},
|
||||
SilenceErrors: true,
|
||||
SilenceUsage: true,
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/aykhans/dodo/config"
|
||||
customerrors "github.com/aykhans/dodo/custom_errors"
|
||||
"github.com/aykhans/dodo/utils"
|
||||
)
|
||||
|
||||
func JSONConfigReader(filePath string) (*config.JSONConfig, error) {
|
||||
@ -13,10 +14,11 @@ 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{
|
||||
Config: config.Config{
|
||||
NoProxyCheck: utils.NewNoneOption[bool](),
|
||||
},
|
||||
}
|
||||
err = json.Unmarshal(data, &jsonConf)
|
||||
|
||||
if err != nil {
|
||||
|
@ -47,15 +47,15 @@ func getClients(
|
||||
}
|
||||
|
||||
clients = append(clients, &fasthttp.HostClient{
|
||||
MaxConns: int(maxConns),
|
||||
IsTLS: isTLS,
|
||||
Addr: addr,
|
||||
Dial: dialFunc,
|
||||
MaxIdleConnDuration: timeout,
|
||||
MaxConnDuration: timeout,
|
||||
WriteTimeout: timeout,
|
||||
ReadTimeout: timeout,
|
||||
},
|
||||
MaxConns: int(maxConns),
|
||||
IsTLS: isTLS,
|
||||
Addr: addr,
|
||||
Dial: dialFunc,
|
||||
MaxIdleConnDuration: timeout,
|
||||
MaxConnDuration: timeout,
|
||||
WriteTimeout: timeout,
|
||||
ReadTimeout: timeout,
|
||||
},
|
||||
)
|
||||
}
|
||||
return clients
|
||||
|
@ -2,6 +2,7 @@ package requests
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -24,6 +25,8 @@ import (
|
||||
// - 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) {
|
||||
fmt.Println("No Proxy Check:", requestConfig.NoProxyCheck)
|
||||
|
||||
checkConnectionCtx, checkConnectionCtxCancel := context.WithTimeout(ctx, 8*time.Second)
|
||||
if !checkConnection(checkConnectionCtx) {
|
||||
checkConnectionCtxCancel()
|
||||
|
@ -5,83 +5,49 @@ import (
|
||||
"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.
|
||||
type Option[T any] struct {
|
||||
value T
|
||||
// none indicates whether the Option is None (i.e., has no value).
|
||||
none bool
|
||||
none bool
|
||||
}
|
||||
|
||||
func (o *option[T]) IsNone() 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) {
|
||||
func (o *Option[T]) ValueOrErr() (*T, error) {
|
||||
if o.IsNone() {
|
||||
return o.value, errors.New("Option is None")
|
||||
return nil, errors.New("Option is None")
|
||||
}
|
||||
return o.value, nil
|
||||
return &o.value, nil
|
||||
}
|
||||
|
||||
// If the Option is None, it will return the default value.
|
||||
func (o *option[T]) ValueOr(def T) T {
|
||||
func (o *Option[T]) ValueOr(def *T) *T {
|
||||
if o.IsNone() {
|
||||
return def
|
||||
}
|
||||
return o.value
|
||||
return &o.value
|
||||
}
|
||||
|
||||
// If the Option is None, it will panic.
|
||||
func (o *option[T]) ValueOrPanic() T {
|
||||
func (o *Option[T]) ValueOrPanic() *T {
|
||||
if o.IsNone() {
|
||||
panic("Option is None")
|
||||
}
|
||||
return o.value
|
||||
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()
|
||||
func (o *Option[T]) UnmarshalJSON(data []byte) error {
|
||||
if string(data) == "null" {
|
||||
o.none = true
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &o.value); err != nil {
|
||||
o.SetNone()
|
||||
return err
|
||||
}
|
||||
o.none = false
|
||||
return nil
|
||||
return json.Unmarshal(data, &o.value)
|
||||
}
|
||||
|
||||
func NewOption[T NonNilT](value T) *option[T] {
|
||||
return &option[T]{value: value}
|
||||
func NewOption[T any](value T) Option[T] {
|
||||
return Option[T]{value: value}
|
||||
}
|
||||
|
||||
func NewNoneOption[T NonNilT]() *option[T] {
|
||||
return &option[T]{none: true}
|
||||
func NewNoneOption[T any]() Option[T] {
|
||||
return Option[T]{none: true}
|
||||
}
|
||||
|
Reference in New Issue
Block a user