Skip to content

Commit bea2a81

Browse files
authored
Merge pull request #104 from aykhans/chore/refactor-ci
🔧 Refactor .golangci and Taskfile
2 parents 53ed486 + 0b9c32a commit bea2a81

File tree

17 files changed

+71
-66
lines changed

17 files changed

+71
-66
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
with:
2020
go-version: stable
2121
- name: golangci-lint
22-
uses: golangci/golangci-lint-action@v6
22+
uses: golangci/golangci-lint-action@v7
2323
with:
24-
version: v1.64
24+
version: v2.0.2
2525
args: --timeout=10m --config=.golangci.yml

.golangci.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
version: "2"
2+
13
run:
24
go: "1.24"
35
concurrency: 8
46
timeout: 10m
57

68
linters:
7-
disable-all: true
9+
default: none
810
enable:
911
- asasalint
1012
- asciicheck
1113
- errcheck
12-
- gofmt
13-
- goimports
1414
- gomodguard
1515
- goprintffuncname
1616
- govet
@@ -21,7 +21,13 @@ linters:
2121
- prealloc
2222
- reassign
2323
- staticcheck
24-
- typecheck
2524
- unconvert
2625
- unused
2726
- whitespace
27+
28+
settings:
29+
staticcheck:
30+
checks:
31+
- "all"
32+
- "-S1002"
33+
- "-ST1000"

Taskfile.yaml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,26 @@ vars:
2020
tasks:
2121
run: go run main.go
2222

23+
fmt: gofmt -w -d .
24+
2325
lint: golangci-lint run
2426

2527
build: go build -ldflags "-s -w" -o "dodo"
2628

27-
fmt: gofmt -w -d .
28-
2929
build-all:
3030
silent: true
3131
cmds:
3232
- rm -rf binaries
33-
- for: { var: PLATFORMS, as: PLATFORM }
34-
cmd: |
35-
{{ $ext := "" }}
36-
37-
{{ if eq $.PLATFORM.os "windows" }}
38-
{{ $ext = ".exe" }}
39-
{{ end }}
40-
41-
{{range $arch := $.PLATFORM.archs}}
42-
echo "Building for {{$.PLATFORM.os}}/{{$arch}}"
43-
GOOS={{$.PLATFORM.os}} GOARCH={{$arch}} go build -ldflags "-s -w" -o "./binaries/dodo-{{$.PLATFORM.os}}-{{$arch}}{{$ext}}"
44-
{{end}}
33+
- |
34+
{{ $ext := "" }}
35+
{{- range $platform := .PLATFORMS }}
36+
{{- if eq $platform.os "windows" }}
37+
{{ $ext = ".exe" }}
38+
{{- end }}
39+
40+
{{- range $arch := $platform.archs }}
41+
echo "Building for {{$platform.os}}/{{$arch}}"
42+
GOOS={{$platform.os}} GOARCH={{$arch}} go build -ldflags "-s -w" -o "./binaries/dodo-{{$platform.os}}-{{$arch}}{{$ext}}"
43+
{{- end }}
44+
{{- end }}
45+
- echo -e "\033[32m*** Build completed ***\033[0m"

config/config.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,45 +145,45 @@ func NewConfig() *Config {
145145
return &Config{}
146146
}
147147

148-
func (c *Config) Validate() []error {
148+
func (config *Config) Validate() []error {
149149
var errs []error
150-
if utils.IsNilOrZero(c.URL) {
150+
if utils.IsNilOrZero(config.URL) {
151151
errs = append(errs, errors.New("request URL is required"))
152152
} else {
153-
if c.URL.Scheme == "" {
154-
c.URL.Scheme = "http"
153+
if config.URL.Scheme == "" {
154+
config.URL.Scheme = "http"
155155
}
156-
if c.URL.Scheme != "http" && c.URL.Scheme != "https" {
156+
if config.URL.Scheme != "http" && config.URL.Scheme != "https" {
157157
errs = append(errs, errors.New("request URL scheme must be http or https"))
158158
}
159159

160160
urlParams := types.Params{}
161-
for key, values := range c.URL.Query() {
161+
for key, values := range config.URL.Query() {
162162
for _, value := range values {
163163
urlParams = append(urlParams, types.KeyValue[string, []string]{
164164
Key: key,
165165
Value: []string{value},
166166
})
167167
}
168168
}
169-
c.Params = append(urlParams, c.Params...)
170-
c.URL.RawQuery = ""
169+
config.Params = append(urlParams, config.Params...)
170+
config.URL.RawQuery = ""
171171
}
172172

173-
if utils.IsNilOrZero(c.Method) {
173+
if utils.IsNilOrZero(config.Method) {
174174
errs = append(errs, errors.New("request method is required"))
175175
}
176-
if utils.IsNilOrZero(c.Timeout) {
176+
if utils.IsNilOrZero(config.Timeout) {
177177
errs = append(errs, errors.New("request timeout must be greater than 0"))
178178
}
179-
if utils.IsNilOrZero(c.DodosCount) {
179+
if utils.IsNilOrZero(config.DodosCount) {
180180
errs = append(errs, errors.New("dodos count must be greater than 0"))
181181
}
182-
if utils.IsNilOrZero(c.Duration) && utils.IsNilOrZero(c.RequestCount) {
182+
if utils.IsNilOrZero(config.Duration) && utils.IsNilOrZero(config.RequestCount) {
183183
errs = append(errs, errors.New("you should provide at least one of duration or request count"))
184184
}
185185

186-
for i, proxy := range c.Proxies {
186+
for i, proxy := range config.Proxies {
187187
if proxy.String() == "" {
188188
errs = append(errs, fmt.Errorf("proxies[%d]: proxy cannot be empty", i))
189189
} else if schema := proxy.Scheme; !slices.Contains(SupportedProxySchemes, schema) {

config/file.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (config *Config) ReadFile(filePath types.ConfigFile) error {
3434
if err != nil {
3535
return fmt.Errorf("failed to fetch config file from %s", filePath)
3636
}
37-
defer resp.Body.Close()
37+
defer func() { _ = resp.Body.Close() }()
3838

3939
data, err = io.ReadAll(io.Reader(resp.Body))
4040
if err != nil {
@@ -47,9 +47,10 @@ func (config *Config) ReadFile(filePath types.ConfigFile) error {
4747
}
4848
}
4949

50-
if fileExt == "json" {
50+
switch fileExt {
51+
case "json":
5152
return parseJSONConfig(data, config)
52-
} else if fileExt == "yml" || fileExt == "yaml" {
53+
case "yml", "yaml":
5354
return parseYAMLConfig(data, config)
5455
}
5556
}

requests/client.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ func getClients(
7272
func getDialFunc(proxy *url.URL, timeout time.Duration) (fasthttp.DialFunc, error) {
7373
var dialer fasthttp.DialFunc
7474

75-
if proxy.Scheme == "socks5" || proxy.Scheme == "socks5h" {
75+
switch proxy.Scheme {
76+
case "socks5", "socks5h":
7677
dialer = fasthttpproxy.FasthttpSocksDialerDualStack(proxy.String())
77-
} else if proxy.Scheme == "http" {
78+
case "http":
7879
dialer = fasthttpproxy.FasthttpHTTPDialerDualStackTimeout(proxy.String(), timeout)
79-
} else {
80+
default:
8081
return nil, errors.New("unsupported proxy scheme")
8182
}
8283
return dialer, nil

requests/run.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ func releaseDodos(
6565
wg sync.WaitGroup
6666
streamWG sync.WaitGroup
6767
requestCountPerDodo uint
68-
dodosCount uint = requestConfig.GetValidDodosCountForRequests()
69-
responses = make([][]*Response, dodosCount)
70-
increase = make(chan int64, requestConfig.RequestCount)
68+
dodosCount = requestConfig.GetValidDodosCountForRequests()
69+
responses = make([][]*Response, dodosCount)
70+
increase = make(chan int64, requestConfig.RequestCount)
7171
)
7272

7373
wg.Add(int(dodosCount))

types/body.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ type Body []string
1313
func (body Body) String() string {
1414
var buffer bytes.Buffer
1515
if len(body) == 0 {
16-
return string(buffer.Bytes())
16+
return buffer.String()
1717
}
1818

1919
if len(body) == 1 {
2020
buffer.WriteString(body[0])
21-
return string(buffer.Bytes())
21+
return buffer.String()
2222
}
2323

2424
buffer.WriteString(text.FgBlue.Sprint("Random") + "[\n")
@@ -41,7 +41,7 @@ func (body Body) String() string {
4141
}
4242

4343
buffer.WriteString("\n]")
44-
return string(buffer.Bytes())
44+
return buffer.String()
4545
}
4646

4747
func (body *Body) UnmarshalJSON(b []byte) error {

types/cookies.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type Cookies []KeyValue[string, []string]
1414
func (cookies Cookies) String() string {
1515
var buffer bytes.Buffer
1616
if len(cookies) == 0 {
17-
return string(buffer.Bytes())
17+
return buffer.String()
1818
}
1919

2020
indent := " "
@@ -53,7 +53,7 @@ func (cookies Cookies) String() string {
5353
buffer.WriteString(",\n" + text.FgGreen.Sprintf("+%d cookies", remainingPairs))
5454
}
5555

56-
return string(buffer.Bytes())
56+
return buffer.String()
5757
}
5858

5959
func (cookies *Cookies) AppendByKey(key, value string) {

types/duration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (duration *Duration) UnmarshalJSON(b []byte) error {
3232
}
3333

3434
func (duration Duration) MarshalJSON() ([]byte, error) {
35-
return json.Marshal(duration.Duration.String())
35+
return json.Marshal(duration.String())
3636
}
3737

3838
func (duration *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error {

0 commit comments

Comments
 (0)