Skip to content

Commit 9d077b0

Browse files
authored
lint by golangci-lint (#3080)
1 parent f4e4fbe commit 9d077b0

File tree

122 files changed

+947
-1331
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+947
-1331
lines changed

.circleci/config.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ version: 2
22
jobs:
33
go-version-latest:
44
docker:
5-
- image: cimg/go:1.18-node
5+
- image: cimg/go:1.19-node
6+
resource_class: large
67
steps:
78
- checkout
89
- run: make
910
- run: make alltest
1011
go-version-last:
1112
docker:
12-
- image: cimg/go:1.17-node
13+
- image: cimg/go:1.18-node
14+
resource_class: large
1315
steps:
1416
- checkout
1517
- run: make
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- dev
7+
pull_request:
8+
permissions:
9+
contents: read
10+
# Optional: allow read access to pull request. Use with `only-new-issues` option.
11+
pull-requests: read
12+
jobs:
13+
golangci:
14+
name: lint
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/setup-go@v3
18+
with:
19+
go-version: 1.19
20+
- uses: actions/checkout@v3
21+
- name: golangci-lint
22+
uses: golangci/golangci-lint-action@v3
23+
with:
24+
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
25+
version: v1.49.0
26+
27+
# Optional: golangci-lint command line arguments.
28+
# args: --issues-exit-code=0
29+
30+
# Optional: show only new issues if it's a pull request. The default value is `false`.
31+
# only-new-issues: true
32+
33+
# Optional: if set to true then the all caching functionality will be complete disabled,
34+
# takes precedence over all other caching options.
35+
# skip-cache: true
36+
37+
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
38+
# skip-pkg-cache: true
39+
40+
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
41+
# skip-build-cache: true

.github/workflows/goreleaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Set up Go
1616
uses: actions/setup-go@v2
1717
with:
18-
go-version: 1.18
18+
go-version: 1.19
1919

2020
- run: |
2121
# https://github.com/actions/setup-go/issues/107

.golangci.yml

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
service:
2+
# When updating this, also update the version stored in docker/build-tools/Dockerfile in the istio/tools repo.
3+
golangci-lint-version: 1.49.x # use the fixed version to not introduce new linters unexpectedly
4+
5+
run:
6+
concurrency: 4
7+
# timeout for analysis, e.g. 30s, 5m, default is 1m
8+
deadline: 20m
9+
build-tags:
10+
- integ
11+
- integfuzz
12+
# which dirs to skip: they won't be analyzed;
13+
# can use regexp here: generated.*, regexp is applied on full path;
14+
# default value is empty list, but next dirs are always skipped independently
15+
# from this option's value:
16+
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
17+
skip-dirs:
18+
- genfiles$
19+
- vendor$
20+
- bin$
21+
22+
# which files to skip: they will be analyzed, but issues from them
23+
# won't be reported. Default value is empty list, but there is
24+
# no need to include all autogenerated files, we confidently recognize
25+
# autogenerated files. If it's not please let us know.
26+
skip-files:
27+
- ".*\\.pb\\.go"
28+
- ".*\\.gen\\.go"
29+
30+
linters:
31+
disable-all: true
32+
enable:
33+
- unused
34+
- errcheck
35+
- exportloopref
36+
- gocritic
37+
- gofumpt
38+
- goimports
39+
- revive
40+
- gosimple
41+
- govet
42+
- ineffassign
43+
- lll
44+
- misspell
45+
- staticcheck
46+
- stylecheck
47+
- typecheck
48+
- unconvert
49+
- unparam
50+
- gci
51+
- bodyclose
52+
- gosec
53+
- asciicheck
54+
- prealloc
55+
- predeclared
56+
- makezero
57+
fast: false
58+
59+
linters-settings:
60+
errcheck:
61+
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
62+
# default is false: such cases aren't reported by default.
63+
check-type-assertions: false
64+
65+
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
66+
# default is false: such cases aren't reported by default.
67+
check-blank: false
68+
govet:
69+
# report about shadowed variables
70+
check-shadowing: false
71+
maligned:
72+
# print struct with more effective memory layout or not, false by default
73+
suggest-new: true
74+
misspell:
75+
# Correct spellings using locale preferences for US or UK.
76+
# Default is to use a neutral variety of English.
77+
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
78+
locale: US
79+
ignore-words:
80+
- cancelled
81+
- marshalled
82+
lll:
83+
# max line length, lines longer will be reported. Default is 120.
84+
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
85+
line-length: 160
86+
# tab width in spaces. Default to 1.
87+
tab-width: 1
88+
gocritic:
89+
disabled-checks:
90+
- exitAfterDefer
91+
unused:
92+
check-exported: false
93+
unparam:
94+
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
95+
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
96+
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
97+
# with golangci-lint call it on a directory with the changed file.
98+
check-exported: false
99+
gci:
100+
sections:
101+
- standard
102+
- default
103+
- prefix(github.com/fatedier/frp/)
104+
gosec:
105+
severity: "low"
106+
confidence: "low"
107+
excludes:
108+
- G102
109+
- G112
110+
- G306
111+
- G401
112+
- G402
113+
- G404
114+
- G501
115+
116+
issues:
117+
# List of regexps of issue texts to exclude, empty list by default.
118+
# But independently from this option we use default exclude patterns,
119+
# it can be disabled by `exclude-use-default: false`. To list all
120+
# excluded by default patterns execute `golangci-lint run --help`
121+
# exclude:
122+
# - composite literal uses unkeyed fields
123+
124+
exclude-rules:
125+
# Exclude some linters from running on test files.
126+
- path: _test\.go$|^tests/|^samples/
127+
linters:
128+
- errcheck
129+
- maligned
130+
131+
# Independently from option `exclude` we use default exclude patterns,
132+
# it can be disabled by this option. To list all
133+
# excluded by default patterns execute `golangci-lint run --help`.
134+
# Default value for this option is true.
135+
exclude-use-default: true
136+
137+
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
138+
max-per-linter: 0
139+
140+
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
141+
max-same-issues: 0

client/admin.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import (
2020
"net/http/pprof"
2121
"time"
2222

23+
"github.com/gorilla/mux"
24+
2325
"github.com/fatedier/frp/assets"
2426
frpNet "github.com/fatedier/frp/pkg/util/net"
25-
26-
"github.com/gorilla/mux"
2727
)
2828

2929
var (
@@ -77,6 +77,8 @@ func (svr *Service) RunAdminServer(address string) (err error) {
7777
return err
7878
}
7979

80-
go server.Serve(ln)
80+
go func() {
81+
_ = server.Serve(ln)
82+
}()
8183
return
8284
}

client/admin_api.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (svr *Service) apiReload(w http.ResponseWriter, r *http.Request) {
4949
log.Info("api response [/api/reload], code [%d]", res.Code)
5050
w.WriteHeader(res.Code)
5151
if len(res.Msg) > 0 {
52-
w.Write([]byte(res.Msg))
52+
_, _ = w.Write([]byte(res.Msg))
5353
}
5454
}()
5555

@@ -68,7 +68,6 @@ func (svr *Service) apiReload(w http.ResponseWriter, r *http.Request) {
6868
return
6969
}
7070
log.Info("success reload conf")
71-
return
7271
}
7372

7473
type StatusResp struct {
@@ -173,7 +172,7 @@ func (svr *Service) apiStatus(w http.ResponseWriter, r *http.Request) {
173172
defer func() {
174173
log.Info("Http response [/api/status]")
175174
buf, _ = json.Marshal(&res)
176-
w.Write(buf)
175+
_, _ = w.Write(buf)
177176
}()
178177

179178
ps := svr.ctl.pm.GetAllProxyStatus()
@@ -202,7 +201,6 @@ func (svr *Service) apiStatus(w http.ResponseWriter, r *http.Request) {
202201
sort.Sort(ByProxyStatusResp(res.STCP))
203202
sort.Sort(ByProxyStatusResp(res.XTCP))
204203
sort.Sort(ByProxyStatusResp(res.SUDP))
205-
return
206204
}
207205

208206
// GET api/config
@@ -214,7 +212,7 @@ func (svr *Service) apiGetConfig(w http.ResponseWriter, r *http.Request) {
214212
log.Info("Http get response [/api/config], code [%d]", res.Code)
215213
w.WriteHeader(res.Code)
216214
if len(res.Msg) > 0 {
217-
w.Write([]byte(res.Msg))
215+
_, _ = w.Write([]byte(res.Msg))
218216
}
219217
}()
220218

@@ -254,7 +252,7 @@ func (svr *Service) apiPutConfig(w http.ResponseWriter, r *http.Request) {
254252
log.Info("Http put response [/api/config], code [%d]", res.Code)
255253
w.WriteHeader(res.Code)
256254
if len(res.Msg) > 0 {
257-
w.Write([]byte(res.Msg))
255+
_, _ = w.Write([]byte(res.Msg))
258256
}
259257
}()
260258

@@ -315,7 +313,7 @@ func (svr *Service) apiPutConfig(w http.ResponseWriter, r *http.Request) {
315313
}
316314
content = strings.Join(newRows, "\n")
317315

318-
err = os.WriteFile(svr.cfgFile, []byte(content), 0644)
316+
err = os.WriteFile(svr.cfgFile, []byte(content), 0o644)
319317
if err != nil {
320318
res.Code = 500
321319
res.Msg = fmt.Sprintf("write content to frpc config file error: %v", err)

client/control.go

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,20 @@ import (
2121
"net"
2222
"runtime/debug"
2323
"strconv"
24-
"sync"
2524
"time"
2625

26+
"github.com/fatedier/golib/control/shutdown"
27+
"github.com/fatedier/golib/crypto"
28+
libdial "github.com/fatedier/golib/net/dial"
29+
fmux "github.com/hashicorp/yamux"
30+
2731
"github.com/fatedier/frp/client/proxy"
2832
"github.com/fatedier/frp/pkg/auth"
2933
"github.com/fatedier/frp/pkg/config"
3034
"github.com/fatedier/frp/pkg/msg"
3135
"github.com/fatedier/frp/pkg/transport"
3236
frpNet "github.com/fatedier/frp/pkg/util/net"
3337
"github.com/fatedier/frp/pkg/util/xlog"
34-
35-
"github.com/fatedier/golib/control/shutdown"
36-
"github.com/fatedier/golib/crypto"
37-
libdial "github.com/fatedier/golib/net/dial"
38-
fmux "github.com/hashicorp/yamux"
3938
)
4039

4140
type Control struct {
@@ -79,8 +78,6 @@ type Control struct {
7978
// The UDP port that the server is listening on
8079
serverUDPPort int
8180

82-
mu sync.RWMutex
83-
8481
xl *xlog.Logger
8582

8683
// service context
@@ -95,8 +92,8 @@ func NewControl(ctx context.Context, runID string, conn net.Conn, session *fmux.
9592
pxyCfgs map[string]config.ProxyConf,
9693
visitorCfgs map[string]config.VisitorConf,
9794
serverUDPPort int,
98-
authSetter auth.Setter) *Control {
99-
95+
authSetter auth.Setter,
96+
) *Control {
10097
// new xlog instance
10198
ctl := &Control{
10299
runID: runID,
@@ -131,7 +128,6 @@ func (ctl *Control) Run() {
131128

132129
// start all visitors
133130
go ctl.vm.Run()
134-
return
135131
}
136132

137133
func (ctl *Control) HandleReqWorkConn(inMsg *msg.ReqWorkConn) {
@@ -400,24 +396,21 @@ func (ctl *Control) worker() {
400396
go ctl.reader()
401397
go ctl.writer()
402398

403-
select {
404-
case <-ctl.closedCh:
405-
// close related channels and wait until other goroutines done
406-
close(ctl.readCh)
407-
ctl.readerShutdown.WaitDone()
408-
ctl.msgHandlerShutdown.WaitDone()
399+
<-ctl.closedCh
400+
// close related channels and wait until other goroutines done
401+
close(ctl.readCh)
402+
ctl.readerShutdown.WaitDone()
403+
ctl.msgHandlerShutdown.WaitDone()
409404

410-
close(ctl.sendCh)
411-
ctl.writerShutdown.WaitDone()
405+
close(ctl.sendCh)
406+
ctl.writerShutdown.WaitDone()
412407

413-
ctl.pm.Close()
414-
ctl.vm.Close()
408+
ctl.pm.Close()
409+
ctl.vm.Close()
415410

416-
close(ctl.closedDoneCh)
417-
if ctl.session != nil {
418-
ctl.session.Close()
419-
}
420-
return
411+
close(ctl.closedDoneCh)
412+
if ctl.session != nil {
413+
ctl.session.Close()
421414
}
422415
}
423416

client/event/event.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import (
66
"github.com/fatedier/frp/pkg/msg"
77
)
88

9-
var (
10-
ErrPayloadType = errors.New("error payload type")
11-
)
9+
var ErrPayloadType = errors.New("error payload type")
1210

1311
type Handler func(payload interface{}) error
1412

0 commit comments

Comments
 (0)