From 439f66eb87a7acf92e73799f90a6b1f422836a4b Mon Sep 17 00:00:00 2001 From: Aykhan Shahsuvarov Date: Thu, 3 Apr 2025 03:07:38 +0400 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=94=A7=20Refactor=20.golangci=20and?= =?UTF-8?q?=20Taskfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .golangci.yml | 4 +++- Taskfile.yaml | 23 ++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index e8e7d48..1b9de2b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,10 +1,12 @@ +version: "2" + run: go: "1.24" concurrency: 8 timeout: 10m linters: - disable-all: true + default: none enable: - asasalint - asciicheck diff --git a/Taskfile.yaml b/Taskfile.yaml index f199bd9..09315aa 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -26,15 +26,16 @@ tasks: silent: true cmds: - rm -rf binaries - - for: { var: PLATFORMS, as: PLATFORM } - cmd: | - {{ $ext := "" }} + - | + {{ $ext := "" }} + {{- range $platform := .PLATFORMS }} + {{- if eq $platform.os "windows" }} + {{ $ext = ".exe" }} + {{- end }} - {{ if eq $.PLATFORM.os "windows" }} - {{ $ext = ".exe" }} - {{ end }} - - {{range $arch := $.PLATFORM.archs}} - echo "Building for {{$.PLATFORM.os}}/{{$arch}}" - GOOS={{$.PLATFORM.os}} GOARCH={{$arch}} go build -ldflags "-s -w" -o "./binaries/dodo-{{$.PLATFORM.os}}-{{$arch}}{{$ext}}" - {{end}} \ No newline at end of file + {{- range $arch := $platform.archs }} + echo "Building for {{$platform.os}}/{{$arch}}" + GOOS={{$platform.os}} GOARCH={{$arch}} go build -ldflags "-s -w" -o "./binaries/dodo-{{$platform.os}}-{{$arch}}{{$ext}}" + {{- end }} + {{- end }} + - echo -e "\033[32m*** Build completed ***\033[0m" From f1ca2041c34e7cb1f1b7ccb71230af081319957b Mon Sep 17 00:00:00 2001 From: Aykhan Shahsuvarov Date: Thu, 3 Apr 2025 04:15:48 +0400 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=94=A7=20bump=20golangci=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/golangci-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index cbbb4cf..d95c740 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -21,5 +21,5 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: v1.64 + version: v1.64.5 args: --timeout=10m --config=.golangci.yml From 09034b5f9ebdbdb900e490ecad2c604a919caea8 Mon Sep 17 00:00:00 2001 From: Aykhan Shahsuvarov Date: Thu, 3 Apr 2025 04:18:53 +0400 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=94=A7=20bump=20golangci/golangci-lin?= =?UTF-8?q?t-action=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/golangci-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index d95c740..349d305 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -19,7 +19,7 @@ jobs: with: go-version: stable - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: version: v1.64.5 args: --timeout=10m --config=.golangci.yml From e80ae9ab24ab012da6100e35a5da86c4dbde48c4 Mon Sep 17 00:00:00 2001 From: Aykhan Shahsuvarov Date: Thu, 3 Apr 2025 04:24:23 +0400 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=94=A7=20bump=20golangci=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/golangci-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 349d305..765c21c 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -21,5 +21,5 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v7 with: - version: v1.64.5 + version: v2.0.2 args: --timeout=10m --config=.golangci.yml From 42d5617e3f2d90541de3fc0a7881b5e8660e9e6e Mon Sep 17 00:00:00 2001 From: Aykhan Shahsuvarov Date: Thu, 3 Apr 2025 05:01:22 +0400 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=8E=A8=20Format=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .golangci.yml | 10 +++++++--- Taskfile.yaml | 4 ++++ config/config.go | 26 +++++++++++++------------- config/file.go | 7 ++++--- requests/client.go | 7 ++++--- requests/run.go | 6 +++--- types/body.go | 6 +++--- types/cookies.go | 4 ++-- types/duration.go | 2 +- types/headers.go | 4 ++-- types/params.go | 4 ++-- types/proxies.go | 6 +++--- types/request_url.go | 4 ++-- types/timeout.go | 2 +- utils/compare.go | 6 +----- utils/slice.go | 6 +++--- 16 files changed, 55 insertions(+), 49 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 1b9de2b..3693c4d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,8 +11,6 @@ linters: - asasalint - asciicheck - errcheck - - gofmt - - goimports - gomodguard - goprintffuncname - govet @@ -23,7 +21,13 @@ linters: - prealloc - reassign - staticcheck - - typecheck - unconvert - unused - whitespace + + settings: + staticcheck: + checks: + - "all" + - "-S1002" + - "-ST1000" diff --git a/Taskfile.yaml b/Taskfile.yaml index 09315aa..f47e679 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -18,6 +18,10 @@ vars: archs: [386, amd64, arm64] tasks: + run: go run main.go + + fmt: gofmt -w -d . + lint: golangci-lint run build: go build -ldflags "-s -w" -o "dodo" diff --git a/config/config.go b/config/config.go index a1a6131..fdda712 100644 --- a/config/config.go +++ b/config/config.go @@ -145,20 +145,20 @@ func NewConfig() *Config { return &Config{} } -func (c *Config) Validate() []error { +func (config *Config) Validate() []error { var errs []error - if utils.IsNilOrZero(c.URL) { + if utils.IsNilOrZero(config.URL) { errs = append(errs, errors.New("request URL is required")) } else { - if c.URL.Scheme == "" { - c.URL.Scheme = "http" + if config.URL.Scheme == "" { + config.URL.Scheme = "http" } - if c.URL.Scheme != "http" && c.URL.Scheme != "https" { + if config.URL.Scheme != "http" && config.URL.Scheme != "https" { errs = append(errs, errors.New("request URL scheme must be http or https")) } urlParams := types.Params{} - for key, values := range c.URL.Query() { + for key, values := range config.URL.Query() { for _, value := range values { urlParams = append(urlParams, types.KeyValue[string, []string]{ Key: key, @@ -166,24 +166,24 @@ func (c *Config) Validate() []error { }) } } - c.Params = append(urlParams, c.Params...) - c.URL.RawQuery = "" + config.Params = append(urlParams, config.Params...) + config.URL.RawQuery = "" } - if utils.IsNilOrZero(c.Method) { + if utils.IsNilOrZero(config.Method) { errs = append(errs, errors.New("request method is required")) } - if utils.IsNilOrZero(c.Timeout) { + if utils.IsNilOrZero(config.Timeout) { errs = append(errs, errors.New("request timeout must be greater than 0")) } - if utils.IsNilOrZero(c.DodosCount) { + if utils.IsNilOrZero(config.DodosCount) { errs = append(errs, errors.New("dodos count must be greater than 0")) } - if utils.IsNilOrZero(c.Duration) && utils.IsNilOrZero(c.RequestCount) { + if utils.IsNilOrZero(config.Duration) && utils.IsNilOrZero(config.RequestCount) { errs = append(errs, errors.New("you should provide at least one of duration or request count")) } - for i, proxy := range c.Proxies { + for i, proxy := range config.Proxies { if proxy.String() == "" { errs = append(errs, fmt.Errorf("proxies[%d]: proxy cannot be empty", i)) } else if schema := proxy.Scheme; !slices.Contains(SupportedProxySchemes, schema) { diff --git a/config/file.go b/config/file.go index bfb4571..abf5e21 100644 --- a/config/file.go +++ b/config/file.go @@ -34,7 +34,7 @@ func (config *Config) ReadFile(filePath types.ConfigFile) error { if err != nil { return fmt.Errorf("failed to fetch config file from %s", filePath) } - defer resp.Body.Close() + defer func() { _ = resp.Body.Close() }() data, err = io.ReadAll(io.Reader(resp.Body)) if err != nil { @@ -47,9 +47,10 @@ func (config *Config) ReadFile(filePath types.ConfigFile) error { } } - if fileExt == "json" { + switch fileExt { + case "json": return parseJSONConfig(data, config) - } else if fileExt == "yml" || fileExt == "yaml" { + case "yml", "yaml": return parseYAMLConfig(data, config) } } diff --git a/requests/client.go b/requests/client.go index a385f78..621490d 100644 --- a/requests/client.go +++ b/requests/client.go @@ -72,11 +72,12 @@ func getClients( func getDialFunc(proxy *url.URL, timeout time.Duration) (fasthttp.DialFunc, error) { var dialer fasthttp.DialFunc - if proxy.Scheme == "socks5" || proxy.Scheme == "socks5h" { + switch proxy.Scheme { + case "socks5", "socks5h": dialer = fasthttpproxy.FasthttpSocksDialerDualStack(proxy.String()) - } else if proxy.Scheme == "http" { + case "http": dialer = fasthttpproxy.FasthttpHTTPDialerDualStackTimeout(proxy.String(), timeout) - } else { + default: return nil, errors.New("unsupported proxy scheme") } return dialer, nil diff --git a/requests/run.go b/requests/run.go index a076671..475fbd6 100644 --- a/requests/run.go +++ b/requests/run.go @@ -58,9 +58,9 @@ func releaseDodos( wg sync.WaitGroup streamWG sync.WaitGroup requestCountPerDodo uint - dodosCount uint = requestConfig.GetValidDodosCountForRequests() - responses = make([][]*Response, dodosCount) - increase = make(chan int64, requestConfig.RequestCount) + dodosCount = requestConfig.GetValidDodosCountForRequests() + responses = make([][]*Response, dodosCount) + increase = make(chan int64, requestConfig.RequestCount) ) wg.Add(int(dodosCount)) diff --git a/types/body.go b/types/body.go index 7bb1c24..83f698f 100644 --- a/types/body.go +++ b/types/body.go @@ -13,12 +13,12 @@ type Body []string func (body Body) String() string { var buffer bytes.Buffer if len(body) == 0 { - return string(buffer.Bytes()) + return buffer.String() } if len(body) == 1 { buffer.WriteString(body[0]) - return string(buffer.Bytes()) + return buffer.String() } buffer.WriteString(text.FgBlue.Sprint("Random") + "[\n") @@ -41,7 +41,7 @@ func (body Body) String() string { } buffer.WriteString("\n]") - return string(buffer.Bytes()) + return buffer.String() } func (body *Body) UnmarshalJSON(b []byte) error { diff --git a/types/cookies.go b/types/cookies.go index 339e2da..d6e1a68 100644 --- a/types/cookies.go +++ b/types/cookies.go @@ -14,7 +14,7 @@ type Cookies []KeyValue[string, []string] func (cookies Cookies) String() string { var buffer bytes.Buffer if len(cookies) == 0 { - return string(buffer.Bytes()) + return buffer.String() } indent := " " @@ -53,7 +53,7 @@ func (cookies Cookies) String() string { buffer.WriteString(",\n" + text.FgGreen.Sprintf("+%d cookies", remainingPairs)) } - return string(buffer.Bytes()) + return buffer.String() } func (cookies *Cookies) AppendByKey(key, value string) { diff --git a/types/duration.go b/types/duration.go index 7eaa44b..814467f 100644 --- a/types/duration.go +++ b/types/duration.go @@ -32,7 +32,7 @@ func (duration *Duration) UnmarshalJSON(b []byte) error { } func (duration Duration) MarshalJSON() ([]byte, error) { - return json.Marshal(duration.Duration.String()) + return json.Marshal(duration.String()) } func (duration *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error { diff --git a/types/headers.go b/types/headers.go index 3df8299..616e021 100644 --- a/types/headers.go +++ b/types/headers.go @@ -14,7 +14,7 @@ type Headers []KeyValue[string, []string] func (headers Headers) String() string { var buffer bytes.Buffer if len(headers) == 0 { - return string(buffer.Bytes()) + return buffer.String() } indent := " " @@ -53,7 +53,7 @@ func (headers Headers) String() string { buffer.WriteString(",\n" + text.FgGreen.Sprintf("+%d headers", remainingPairs)) } - return string(buffer.Bytes()) + return buffer.String() } func (headers *Headers) AppendByKey(key, value string) { diff --git a/types/params.go b/types/params.go index b4db8c1..ef5245b 100644 --- a/types/params.go +++ b/types/params.go @@ -14,7 +14,7 @@ type Params []KeyValue[string, []string] func (params Params) String() string { var buffer bytes.Buffer if len(params) == 0 { - return string(buffer.Bytes()) + return buffer.String() } indent := " " @@ -53,7 +53,7 @@ func (params Params) String() string { buffer.WriteString(",\n" + text.FgGreen.Sprintf("+%d params", remainingPairs)) } - return string(buffer.Bytes()) + return buffer.String() } func (params *Params) AppendByKey(key, value string) { diff --git a/types/proxies.go b/types/proxies.go index 6e0f58b..6080482 100644 --- a/types/proxies.go +++ b/types/proxies.go @@ -14,12 +14,12 @@ type Proxies []url.URL func (proxies Proxies) String() string { var buffer bytes.Buffer if len(proxies) == 0 { - return string(buffer.Bytes()) + return buffer.String() } if len(proxies) == 1 { buffer.WriteString(proxies[0].String()) - return string(buffer.Bytes()) + return buffer.String() } buffer.WriteString(text.FgBlue.Sprint("Random") + "[\n") @@ -42,7 +42,7 @@ func (proxies Proxies) String() string { } buffer.WriteString("\n]") - return string(buffer.Bytes()) + return buffer.String() } func (proxies *Proxies) UnmarshalJSON(b []byte) error { diff --git a/types/request_url.go b/types/request_url.go index e194d7b..7594a9a 100644 --- a/types/request_url.go +++ b/types/request_url.go @@ -18,7 +18,7 @@ func (requestURL *RequestURL) UnmarshalJSON(data []byte) error { parsedURL, err := url.Parse(urlStr) if err != nil { - return errors.New("Request URL is invalid") + return errors.New("request URL is invalid") } requestURL.URL = *parsedURL @@ -33,7 +33,7 @@ func (requestURL *RequestURL) UnmarshalYAML(unmarshal func(interface{}) error) e parsedURL, err := url.Parse(urlStr) if err != nil { - return errors.New("Request URL is invalid") + return errors.New("request URL is invalid") } requestURL.URL = *parsedURL diff --git a/types/timeout.go b/types/timeout.go index 9d41e33..6160e13 100644 --- a/types/timeout.go +++ b/types/timeout.go @@ -32,7 +32,7 @@ func (timeout *Timeout) UnmarshalJSON(b []byte) error { } func (timeout Timeout) MarshalJSON() ([]byte, error) { - return json.Marshal(timeout.Duration.String()) + return json.Marshal(timeout.String()) } func (timeout *Timeout) UnmarshalYAML(unmarshal func(interface{}) error) error { diff --git a/utils/compare.go b/utils/compare.go index 6cd12f3..e49389f 100644 --- a/utils/compare.go +++ b/utils/compare.go @@ -6,9 +6,5 @@ func IsNilOrZero[T comparable](value *T) bool { } var zero T - if *value == zero { - return true - } - - return false + return *value == zero } diff --git a/utils/slice.go b/utils/slice.go index 55db732..34f955a 100644 --- a/utils/slice.go +++ b/utils/slice.go @@ -20,9 +20,9 @@ func Flatten[T any](nested [][]*T) []*T { // The returned function isn't thread-safe and should be used in a single-threaded context. func RandomValueCycle[Value any](values []Value, localRand *rand.Rand) func() Value { var ( - clientsCount int = len(values) - currentIndex int = localRand.Intn(clientsCount) - stopIndex int = currentIndex + clientsCount = len(values) + currentIndex = localRand.Intn(clientsCount) + stopIndex = currentIndex ) return func() Value {