mirror of
https://github.com/aykhans/dodo.git
synced 2025-07-17 14:44:02 +00:00
Compare commits
42 Commits
2461e3f847
...
v0.5.2
Author | SHA1 | Date | |
---|---|---|---|
fa55de0cf2 | |||
d392d4a787 | |||
2e6110e54a | |||
48721b4ae7 | |||
fe4a93b394 | |||
0725c1a481 | |||
8d983b4313 | |||
c69c35bef4 | |||
e3cbe1e9b4 | |||
94211eb018 | |||
098c1d8cc4 | |||
a468f663bf | |||
d98fb477d4 | |||
bf169d3eb1 | |||
0335b5cf6e | |||
9c5d7bf135 | |||
ede74c17b2 | |||
565079fe97 | |||
696176e611 | |||
9ea06593f9 | |||
7f7dc07f4c | |||
adc5a34891 | |||
5080e90872 | |||
9679fb1c7a | |||
011c7a7774 | |||
9cfae3bdc1 | |||
7c7302c3c5 | |||
![]() |
5ab2c1b300 | ||
0e93409835 | |||
![]() |
54fc52de14 | ||
e8dc8956f5 | |||
![]() |
d853d6e925 | ||
444b59e4b5 | |||
7a39951402 | |||
d01763f181 | |||
![]() |
eec290758d | ||
3cdd75f830 | |||
![]() |
e8197da5dc | ||
54c2fdd159 | |||
![]() |
9940e3465e | ||
ace66138b3 | |||
![]() |
488b8d46c8 |
86
.github/workflows/publish-docker-image.yml
vendored
Normal file
86
.github/workflows/publish-docker-image.yml
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
name: publish-docker-image
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
# Match stable and pre versions, such as 'v1.0.0', 'v0.23.0-a', 'v0.23.0-a.2', 'v0.23.0-b', 'v0.23.0-b.3'
|
||||
- "v*.*.*"
|
||||
- "v*.*.*-a"
|
||||
- "v*.*.*-a.*"
|
||||
- "v*.*.*-b"
|
||||
- "v*.*.*-b.*"
|
||||
|
||||
jobs:
|
||||
build-and-push-stable-image:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Extract build args
|
||||
# Extract version number and check if it's an pre version
|
||||
run: |
|
||||
if [[ "${GITHUB_REF_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||
echo "PRE_RELEASE=false" >> $GITHUB_ENV
|
||||
else
|
||||
echo "PRE_RELEASE=true" >> $GITHUB_ENV
|
||||
fi
|
||||
echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: aykhans
|
||||
password: ${{ secrets.DOCKER_TOKEN }}
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
install: true
|
||||
version: v0.9.1
|
||||
|
||||
# Metadata for stable versions
|
||||
- name: Docker meta for stable
|
||||
id: meta-stable
|
||||
if: env.PRE_RELEASE == 'false'
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: |
|
||||
aykhans/dodo
|
||||
tags: |
|
||||
type=semver,pattern={{version}},value=${{ env.VERSION }}
|
||||
type=raw,value=stable
|
||||
flavor: |
|
||||
latest=true
|
||||
labels: |
|
||||
org.opencontainers.image.version=${{ env.VERSION }}
|
||||
|
||||
# Metadata for pre versions
|
||||
- name: Docker meta for pre
|
||||
id: meta-pre
|
||||
if: env.PRE_RELEASE == 'true'
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: |
|
||||
aykhans/dodo
|
||||
tags: |
|
||||
type=raw,value=${{ env.VERSION }}
|
||||
labels: |
|
||||
org.opencontainers.image.version=${{ env.VERSION }}
|
||||
|
||||
- name: Build and Push
|
||||
id: docker_build
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: ./
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: ${{ steps.meta-stable.outputs.tags || steps.meta-pre.outputs.tags }}
|
||||
labels: ${{ steps.meta-stable.outputs.labels || steps.meta-pre.outputs.labels }}
|
@@ -1,4 +1,4 @@
|
||||
FROM golang:1.22.6-alpine AS builder
|
||||
FROM golang:1.23.2-alpine AS builder
|
||||
|
||||
WORKDIR /dodo
|
||||
|
||||
|
42
README.md
42
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://raw.githubusercontent.com/aykhans/dodo/main/assets/dodo.png">
|
||||
<img width="30%" height="30%" src="https://ftp.aykhans.me/web/client/pubshares/hB6VSdCnBCr8gFPeiMuCji/browse?path=%2Fdodo.png">
|
||||
</p>
|
||||
|
||||
## Installation
|
||||
@@ -33,7 +33,7 @@ Follow the steps below to build dodo:
|
||||
3. **Build the project:**
|
||||
|
||||
```sh
|
||||
go build -o dodo
|
||||
go build -ldflags "-s -w" -o dodo
|
||||
```
|
||||
|
||||
This will generate an executable named `dodo` in the project directory.
|
||||
@@ -58,13 +58,14 @@ You can find an example config structure in the [config.json](https://github.com
|
||||
{
|
||||
"method": "GET",
|
||||
"url": "https://example.com",
|
||||
"timeout": 10000,
|
||||
"dodos_count": 50,
|
||||
"no_proxy_check": false,
|
||||
"timeout": 2000,
|
||||
"dodos_count": 10,
|
||||
"request_count": 1000,
|
||||
"params": {},
|
||||
"headers": {},
|
||||
"cookies": {},
|
||||
"body": "",
|
||||
"body": [""],
|
||||
"proxies": [
|
||||
{
|
||||
"url": "http://example.com:8080",
|
||||
@@ -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
|
||||
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
|
||||
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 |
|
||||
| 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 |
|
||||
| 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) | - |
|
||||
|
BIN
assets/dodo.png
BIN
assets/dodo.png
Binary file not shown.
Before Width: | Height: | Size: 230 KiB |
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"method": "GET",
|
||||
"url": "https://example.com",
|
||||
"no_proxy_check": true,
|
||||
"timeout": 10000,
|
||||
"dodos_count": 50,
|
||||
"request_count": 1000,
|
||||
|
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
VERSION string = "0.5.1"
|
||||
VERSION string = "0.5.2"
|
||||
DefaultUserAgent string = "Dodo/" + VERSION
|
||||
ProxyCheckURL string = "https://www.google.com"
|
||||
DefaultMethod string = "GET"
|
||||
@@ -21,10 +21,6 @@ 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
|
||||
@@ -37,6 +33,7 @@ type RequestConfig struct {
|
||||
Proxies []Proxy
|
||||
Body []string
|
||||
Yes bool
|
||||
NoProxyCheck bool
|
||||
}
|
||||
|
||||
func (config *RequestConfig) Print() {
|
||||
@@ -47,6 +44,12 @@ 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()
|
||||
@@ -56,16 +59,18 @@ func (config *RequestConfig) Print() {
|
||||
t.AppendSeparator()
|
||||
t.AppendRow(table.Row{"Dodos", config.DodosCount})
|
||||
t.AppendSeparator()
|
||||
t.AppendRow(table.Row{"Request", config.RequestCount})
|
||||
t.AppendRow(table.Row{"Requests", config.RequestCount})
|
||||
t.AppendSeparator()
|
||||
t.AppendRow(table.Row{"Params", utils.MarshalJSON(config.Params, 3)})
|
||||
t.AppendSeparator()
|
||||
t.AppendRow(table.Row{"Headers", utils.MarshalJSON(config.Headers, 3)})
|
||||
t.AppendRow(table.Row{"Headers", utils.MarshalJSON(newHeaders, 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()
|
||||
@@ -87,11 +92,32 @@ 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"`
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
func (config *Config) MergeConfigs(newConfig *Config) {
|
||||
@@ -110,6 +136,9 @@ 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() {
|
||||
@@ -125,6 +154,9 @@ func (config *Config) SetDefaults() {
|
||||
if config.RequestCount == 0 {
|
||||
config.RequestCount = DefaultRequestCount
|
||||
}
|
||||
if config.NoProxyCheck.IsNone() {
|
||||
config.NoProxyCheck = utils.NewOption(false)
|
||||
}
|
||||
}
|
||||
|
||||
type Proxy struct {
|
||||
@@ -134,7 +166,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"`
|
||||
@@ -142,8 +174,21 @@ 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
|
||||
}
|
||||
@@ -162,13 +207,23 @@ 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
|
||||
}
|
||||
|
22
go.mod
22
go.mod
@@ -1,29 +1,29 @@
|
||||
module github.com/aykhans/dodo
|
||||
|
||||
go 1.22.6
|
||||
go 1.23.2
|
||||
|
||||
require (
|
||||
github.com/go-playground/validator/v10 v10.22.1
|
||||
github.com/jedib0t/go-pretty/v6 v6.5.9
|
||||
github.com/go-playground/validator/v10 v10.23.0
|
||||
github.com/jedib0t/go-pretty/v6 v6.6.2
|
||||
github.com/spf13/cobra v1.8.1
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/valyala/fasthttp v1.56.0
|
||||
golang.org/x/net v0.29.0
|
||||
github.com/valyala/fasthttp v1.57.0
|
||||
golang.org/x/net v0.31.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.1.0 // indirect
|
||||
github.com/andybalholm/brotli v1.1.1 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.4 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/klauspost/compress v1.17.9 // indirect
|
||||
github.com/klauspost/compress v1.17.11 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
golang.org/x/crypto v0.27.0 // indirect
|
||||
golang.org/x/sys v0.25.0 // indirect
|
||||
golang.org/x/term v0.24.0 // indirect
|
||||
golang.org/x/text v0.18.0 // indirect
|
||||
golang.org/x/crypto v0.29.0 // indirect
|
||||
golang.org/x/sys v0.27.0 // indirect
|
||||
golang.org/x/term v0.26.0 // indirect
|
||||
golang.org/x/text v0.20.0 // indirect
|
||||
)
|
||||
|
42
go.sum
42
go.sum
@@ -1,5 +1,5 @@
|
||||
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
|
||||
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
|
||||
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
|
||||
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@@ -11,14 +11,14 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o
|
||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA=
|
||||
github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
||||
github.com/go-playground/validator/v10 v10.23.0 h1:/PwmTwZhS0dPkav3cdK9kV1FsAmrL8sThn8IHr/sO+o=
|
||||
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/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/jedib0t/go-pretty/v6 v6.5.9 h1:ACteMBRrrmm1gMsXe9PSTOClQ63IXDUt03H5U+UV8OU=
|
||||
github.com/jedib0t/go-pretty/v6 v6.5.9/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
|
||||
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
|
||||
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
||||
github.com/jedib0t/go-pretty/v6 v6.6.2 h1:27bLj3nRODzaiA7tPIxy9UVWHoPspFfME9XxgwiiNsM=
|
||||
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/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/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||
@@ -37,18 +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/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.56.0 h1:bEZdJev/6LCBlpdORfrLu/WOZXXxvrUQSiyniuaoW8U=
|
||||
github.com/valyala/fasthttp v1.56.0/go.mod h1:sReBt3XZVnudxuLOx4J/fMrJVorWRiWY2koQKgABiVI=
|
||||
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
|
||||
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
|
||||
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
|
||||
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
|
||||
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
|
||||
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM=
|
||||
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
|
||||
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
|
||||
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
github.com/valyala/fasthttp v1.57.0 h1:Xw8SjWGEP/+wAAgyy5XTvgrWlOD1+TxbbvNADYCm1Tg=
|
||||
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/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
||||
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
|
||||
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
|
||||
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
|
||||
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
|
||||
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
|
||||
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
|
||||
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
|
||||
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
|
||||
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/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
13
main.go
13
main.go
@@ -21,8 +21,10 @@ import (
|
||||
|
||||
func main() {
|
||||
validator := validation.NewValidator()
|
||||
conf := config.Config{}
|
||||
jsonConf := config.JSONConfig{}
|
||||
conf := config.NewConfig("", 0, 0, 0, nil)
|
||||
jsonConf := config.NewJSONConfig(
|
||||
config.NewConfig("", 0, 0, 0, nil), nil, nil, nil, nil, nil,
|
||||
)
|
||||
|
||||
cliConf, err := readers.CLIConfigReader()
|
||||
if err != nil || cliConf == nil {
|
||||
@@ -51,11 +53,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(
|
||||
@@ -81,6 +83,7 @@ func main() {
|
||||
Proxies: jsonConf.Proxies,
|
||||
Body: jsonConf.Body,
|
||||
Yes: cliConf.Yes,
|
||||
NoProxyCheck: conf.NoProxyCheck.ValueOrPanic(),
|
||||
}
|
||||
requestConf.Print()
|
||||
if !cliConf.Yes {
|
||||
|
@@ -13,10 +13,11 @@ import (
|
||||
func CLIConfigReader() (*config.CLIConfig, error) {
|
||||
var (
|
||||
returnNil = false
|
||||
cliConfig = &config.CLIConfig{}
|
||||
cliConfig = config.NewCLIConfig(config.NewConfig("", 0, 0, 0, nil), false, "")
|
||||
dodosCount uint
|
||||
requestCount uint
|
||||
timeout uint32
|
||||
noProxyCheck bool
|
||||
rootCmd = &cobra.Command{
|
||||
Use: "dodo [flags]",
|
||||
Example: ` Simple usage only with URL:
|
||||
@@ -26,17 +27,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`,
|
||||
Short: `
|
||||
██████████ ███████ ██████████ ███████
|
||||
░░███░░░░███ ███░░░░░███ ░░███░░░░███ ███░░░░░███
|
||||
░███ ░░███ ███ ░░███ ░███ ░░███ ███ ░░███
|
||||
░███ ░███░███ ░███ ░███ ░███░███ ░███
|
||||
░███ ░███░███ ░███ ░███ ░███░███ ░███
|
||||
░███ ███ ░░███ ███ ░███ ███ ░░███ ███
|
||||
██████████ ░░░███████░ ██████████ ░░░███████░
|
||||
░░░░░░░░░░ ░░░░░░░ ░░░░░░░░░░ ░░░░░░░
|
||||
`,
|
||||
dodo -c /path/to/config/file/config.json -u https://example.com -m POST -d 10 -r 1000 -t 2000 --no-proxy-check -y`,
|
||||
Run: func(cmd *cobra.Command, args []string) {},
|
||||
SilenceErrors: true,
|
||||
SilenceUsage: true,
|
||||
@@ -51,6 +42,7 @@ 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())
|
||||
@@ -68,6 +60,8 @@ func CLIConfigReader() (*config.CLIConfig, error) {
|
||||
cliConfig.RequestCount = requestCount
|
||||
case "timeout":
|
||||
cliConfig.Timeout = timeout
|
||||
case "no-proxy-check":
|
||||
cliConfig.NoProxyCheck = utils.NewOption(noProxyCheck)
|
||||
}
|
||||
})
|
||||
if returnNil {
|
||||
|
@@ -5,7 +5,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/aykhans/dodo/config"
|
||||
"github.com/aykhans/dodo/custom_errors"
|
||||
customerrors "github.com/aykhans/dodo/custom_errors"
|
||||
)
|
||||
|
||||
func JSONConfigReader(filePath string) (*config.JSONConfig, error) {
|
||||
@@ -13,7 +13,10 @@ func JSONConfigReader(filePath string) (*config.JSONConfig, error) {
|
||||
if err != nil {
|
||||
return nil, customerrors.OSErrorFormater(err)
|
||||
}
|
||||
jsonConf := &config.JSONConfig{}
|
||||
jsonConf := config.NewJSONConfig(
|
||||
config.NewConfig("", 0, 0, 0, nil),
|
||||
nil, nil, nil, nil, nil,
|
||||
)
|
||||
err = json.Unmarshal(data, &jsonConf)
|
||||
|
||||
if err != nil {
|
||||
|
@@ -26,11 +26,42 @@ func getClients(
|
||||
dodosCount uint,
|
||||
maxConns uint,
|
||||
yes bool,
|
||||
noProxyCheck bool,
|
||||
URL *url.URL,
|
||||
) []*fasthttp.HostClient {
|
||||
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(
|
||||
ctx, proxies, timeout, dodosCount, maxConns, URL,
|
||||
)
|
||||
|
@@ -38,6 +38,7 @@ 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 {
|
||||
|
87
utils/types.go
Normal file
87
utils/types.go
Normal file
@@ -0,0 +1,87 @@
|
||||
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}
|
||||
}
|
Reference in New Issue
Block a user