mirror of
https://github.com/aykhans/dodo.git
synced 2025-04-20 19:13:06 +00:00
Compare commits
No commits in common. "2e6110e54aa1448a2602dda6bfd70a57497dedd7" and "0725c1a4810f7440f86f3ef7a164ef0d2141c740" have entirely different histories.
2e6110e54a
...
0725c1a481
@ -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
|
||||
|
BIN
assets/dodo.png
Normal file
BIN
assets/dodo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 230 KiB |
@ -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
|
||||
}
|
||||
|
12
main.go
12
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(
|
||||
|
@ -12,8 +12,12 @@ import (
|
||||
|
||||
func CLIConfigReader() (*config.CLIConfig, error) {
|
||||
var (
|
||||
returnNil = false
|
||||
cliConfig = config.NewCLIConfig(config.NewConfig("", 0, 0, 0, nil), false, "")
|
||||
returnNil = false
|
||||
cliConfig = &config.CLIConfig{
|
||||
Config: config.Config{
|
||||
NoProxyCheck: utils.NewNoneOption[bool](),
|
||||
},
|
||||
}
|
||||
dodosCount uint
|
||||
requestCount uint
|
||||
timeout uint32
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user