Skip to content

Commit 30b1c5f

Browse files
committed
refactor: enforce stricter linter settings
Signed-off-by: Christian Stewart <christian@aperture.us>
1 parent b3853e2 commit 30b1c5f

27 files changed

+206
-338
lines changed

.golangci.yml

+62
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,67 @@
1+
linters:
2+
enable:
3+
- depguard
4+
- goimports
5+
- gosec
6+
- gosimple
7+
- govet
8+
- importas
9+
- ineffassign
10+
- misspell
11+
- revive
12+
- staticcheck
13+
- typecheck
14+
- unconvert
15+
- unused
16+
17+
disable:
18+
- errcheck
19+
20+
run:
21+
concurrency: 4
22+
modules-download-mode: vendor
23+
24+
skip-dirs:
25+
- hack
26+
127
linters-settings:
228
staticcheck:
329
checks:
430
- all
531
- '-SA1012' # Allow passing nil contexts.
32+
33+
importas:
34+
# Do not allow unaliased imports of aliased packages.
35+
no-unaliased: true
36+
37+
maligned:
38+
suggest-new: true
39+
40+
depguard:
41+
rules:
42+
main:
43+
deny:
44+
- pkg: io/ioutil
45+
desc: The io/ioutil package has been deprecated, see https://go.dev/doc/go1.16#ioutil
46+
- pkg: "github.com/stretchr/testify/assert"
47+
desc: Use "gotest.tools/v3/assert" instead
48+
- pkg: "github.com/stretchr/testify/require"
49+
desc: Use "gotest.tools/v3/assert" instead
50+
- pkg: "github.com/stretchr/testify/suite"
51+
desc: Do not use
52+
53+
revive:
54+
rules:
55+
- name: package-comments
56+
disabled: true
57+
58+
gosec:
59+
excludes:
60+
- G306 # Allow WriteFile permissions to be 0644.
61+
62+
issues:
63+
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
64+
max-issues-per-linter: 0
65+
66+
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
67+
max-same-issues: 0

Makefile

+19-37
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ PROTOWRAP=hack/bin/protowrap
55
PROTOC_GEN_GO=hack/bin/protoc-gen-go
66
PROTOC_GEN_STARPC=hack/bin/protoc-gen-go-starpc
77
PROTOC_GEN_VTPROTO=hack/bin/protoc-gen-go-vtproto
8-
PROTOC_GEN_GO_DRPC=hack/bin/protoc-gen-go-drpc
98
GOIMPORTS=hack/bin/goimports
9+
GOFUMPT=hack/bin/gofumpt
1010
GOLANGCI_LINT=hack/bin/golangci-lint
1111
GO_MOD_OUTDATED=hack/bin/go-mod-outdated
12-
WASMSERVE=hack/bin/wasmserve
13-
GORELEASER=hack/bin/goreleaser
1412
GOLIST=go list -f "{{ .Dir }}" -m
1513

1614
export GO111MODULE=on
17-
undefine GOARCH
1815
undefine GOOS
16+
undefine GOARCH
1917

2018
all:
2119

@@ -34,12 +32,6 @@ $(PROTOC_GEN_VTPROTO):
3432
-o ./bin/protoc-gen-go-vtproto \
3533
github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto
3634

37-
$(PROTOC_GEN_GO_DRPC):
38-
cd ./hack; \
39-
go build -v \
40-
-o ./bin/protoc-gen-go-drpc \
41-
storj.io/drpc/cmd/protoc-gen-go-drpc
42-
4335
$(PROTOC_GEN_STARPC):
4436
cd ./hack; \
4537
go build -v \
@@ -52,6 +44,12 @@ $(GOIMPORTS):
5244
-o ./bin/goimports \
5345
golang.org/x/tools/cmd/goimports
5446

47+
$(GOFUMPT):
48+
cd ./hack; \
49+
go build -v \
50+
-o ./bin/gofumpt \
51+
mvdan.cc/gofumpt
52+
5553
$(PROTOWRAP):
5654
cd ./hack; \
5755
go build -v \
@@ -70,20 +68,8 @@ $(GO_MOD_OUTDATED):
7068
-o ./bin/go-mod-outdated \
7169
github.com/psampaz/go-mod-outdated
7270

73-
$(WASMSERVE):
74-
cd ./hack; \
75-
go build -v \
76-
-o ./bin/wasmserve \
77-
github.com/hajimehoshi/wasmserve
78-
79-
$(GORELEASER):
80-
cd ./hack; \
81-
go build -v \
82-
-o ./bin/goreleaser \
83-
github.com/goreleaser/goreleaser
84-
8571
.PHONY: gengo
86-
gengo: $(GOIMPORTS) $(PROTOWRAP) $(PROTOC_GEN_GO) $(PROTOC_GEN_VTPROTO) $(PROTOC_GEN_GO_DRPC) $(PROTOC_GEN_STARPC)
72+
gengo: vendor $(GOIMPORTS) $(PROTOWRAP) $(PROTOC_GEN_GO) $(PROTOC_GEN_VTPROTO) $(PROTOC_GEN_STARPC)
8773
shopt -s globstar; \
8874
set -eo pipefail; \
8975
export PROJECT=$$(go list -m); \
@@ -96,10 +82,6 @@ gengo: $(GOIMPORTS) $(PROTOWRAP) $(PROTOC_GEN_GO) $(PROTOC_GEN_VTPROTO) $(PROTOC
9682
--go_out=$$(pwd)/vendor \
9783
--go-vtproto_out=$$(pwd)/vendor \
9884
--go-vtproto_opt=features=marshal+unmarshal+size+equal+clone \
99-
--go-drpc_out=$$(pwd)/vendor \
100-
--go-drpc_opt=json=false \
101-
--go-drpc_opt=protolib=github.com/golang/protobuf/proto \
102-
--go-drpc_opt=protolib=github.com/planetscale/vtprotobuf/codec/drpc \
10385
--go-starpc_out=$$(pwd)/vendor \
10486
--proto_path $$(pwd)/vendor \
10587
--print_structure \
@@ -116,7 +98,7 @@ node_modules:
11698
yarn install
11799

118100
.PHONY: gents
119-
gents: $(PROTOWRAP) node_modules
101+
gents: vendor $(PROTOWRAP) node_modules
120102
shopt -s globstar; \
121103
set -eo pipefail; \
122104
export PROJECT=$$(go list -m); \
@@ -146,10 +128,10 @@ gents: $(PROTOWRAP) node_modules
146128
xargs printf -- \
147129
"$$(pwd)/vendor/$${PROJECT}/%s "); \
148130
rm $$(pwd)/vendor/$${PROJECT} || true
149-
npm run format
131+
npm run format:js
150132

151133
.PHONY: genproto
152-
genproto: gengo gents
134+
genproto: gents gengo
153135

154136
.PHONY: gen
155137
gen: genproto
@@ -170,15 +152,15 @@ lint: $(GOLANGCI_LINT)
170152
fix: $(GOLANGCI_LINT)
171153
$(GOLANGCI_LINT) run --fix --timeout=10m
172154

173-
.PHONY: serve-example
174-
serve-example: $(WASMSERVE)
175-
$(WASMSERVE) -http ":8090" ./examples/websocket-browser-link/browser
155+
.PHONY: format
156+
format: $(GOFUMPT) $(GOIMPORTS)
157+
$(GOIMPORTS) -w ./
158+
$(GOFUMPT) -w ./
176159

177160
.PHONY: test
178161
test:
179162
go test -v ./...
180163

181-
.PHONY: release
182-
release: $(GORELEASER)
183-
$(GORELEASER) release --clean
184-
164+
.PHONY: serve-example
165+
serve-example: $(WASMSERVE)
166+
$(WASMSERVE) -http ":8090" ./examples/websocket-browser-link/browser

cli/daemonflags.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (a *DaemonArgs) ApplyToConfigSet(confSet configset.ConfigSet, overwrite boo
102102
}
103103
if len(a.EstablishPeers.Value()) != 0 {
104104
establishConf := &link_establish_controller.Config{
105-
PeerIds: []string(a.EstablishPeers.Value()),
105+
PeerIds: a.EstablishPeers.Value(),
106106
}
107107
if err := establishConf.Validate(); err != nil {
108108
return errors.Wrap(err, "establish-peers")

cmd/bifrost/cmd_daemon.go

+19-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88
"net/http"
99
"os"
1010
"runtime"
11+
"time"
12+
13+
"net/http/pprof"
1114

1215
bcli "github.com/aperturerobotics/bifrost/cli"
1316
"github.com/aperturerobotics/bifrost/daemon"
@@ -26,10 +29,6 @@ import (
2629
"github.com/pkg/errors"
2730
"github.com/sirupsen/logrus"
2831
"github.com/urfave/cli/v2"
29-
30-
// _ enables the profiling endpoints
31-
32-
_ "net/http/pprof"
3332
)
3433

3534
var daemonFlags struct {
@@ -235,7 +234,22 @@ func runDaemon(c *cli.Context) error {
235234
runtime.SetMutexProfileFraction(1)
236235
go func() {
237236
le.Debugf("profiling listener running: %s", daemonFlags.ProfListen)
238-
err := http.ListenAndServe(daemonFlags.ProfListen, nil)
237+
mux := http.NewServeMux()
238+
239+
// Register pprof handlers
240+
mux.HandleFunc("/debug/pprof/", pprof.Index)
241+
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
242+
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
243+
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
244+
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
245+
// Manually add support for paths linked to by index page at /debug/pprof/
246+
mux.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
247+
mux.Handle("/debug/pprof/heap", pprof.Handler("heap"))
248+
mux.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
249+
mux.Handle("/debug/pprof/block", pprof.Handler("block"))
250+
251+
server := &http.Server{Addr: daemonFlags.ProfListen, Handler: mux, ReadHeaderTimeout: time.Second * 10}
252+
err := server.ListenAndServe()
239253
le.WithError(err).Warn("profiling listener exited")
240254
}()
241255
}

go.mod

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
module github.com/aperturerobotics/bifrost
22

3-
go 1.21
3+
go 1.22
4+
5+
toolchain go1.22.1
46

57
require (
6-
github.com/aperturerobotics/controllerbus v0.36.8 // latest
8+
github.com/aperturerobotics/controllerbus v0.37.0 // latest
79
github.com/aperturerobotics/entitygraph v0.7.0
810
github.com/aperturerobotics/starpc v0.27.3 // latest
911
github.com/aperturerobotics/timestamp v0.8.2
1012
github.com/aperturerobotics/ts-proto-common-types v0.20.2 // latest
11-
github.com/aperturerobotics/util v1.15.3 // master
13+
github.com/aperturerobotics/util v1.16.0 // master
1214
)
1315

1416
// aperture: use compatibility forks

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ github.com/aperturerobotics/bifrost-nats-client v1.10.1-0.20200831103200-24c3d04
66
github.com/aperturerobotics/bifrost-nats-client v1.10.1-0.20200831103200-24c3d0464e58/go.mod h1:ougcjYEZDYV8pVtaNbA5sgYDukkYHyKtSsW/T3B13j0=
77
github.com/aperturerobotics/bifrost-nats-server/v2 v2.1.8-0.20221228081037-b7c2df0c151f h1:bmScByQNGDPPy9T+zdwu816XaCbFtD5UDyqZMRiHJ80=
88
github.com/aperturerobotics/bifrost-nats-server/v2 v2.1.8-0.20221228081037-b7c2df0c151f/go.mod h1:kIcZtLpq4UIZzOqduYLm1mYU1nuMBtN6XuDCtQ21QT8=
9-
github.com/aperturerobotics/controllerbus v0.36.8 h1:s2345jsYjrhXUzfWUJDkwIgLmeX456U4E0jg+ktafKA=
10-
github.com/aperturerobotics/controllerbus v0.36.8/go.mod h1:Z+jw8kAx5+aLQYiugd1OnBJIkUaDX4RdQkDleozw3i0=
9+
github.com/aperturerobotics/controllerbus v0.37.0 h1:0Jut71UFBNeQywGy6S+esdtsGSMn6SvSpj3qlu1bwP4=
10+
github.com/aperturerobotics/controllerbus v0.37.0/go.mod h1:NJITG4lLK3lDI+GdhxjG9dyA9kxOLJzjajkNRs5hctc=
1111
github.com/aperturerobotics/entitygraph v0.7.0 h1:VqLRJL09a5K+Wm776TVgYNcPWVSTAg4z2WWqKBJ3WTA=
1212
github.com/aperturerobotics/entitygraph v0.7.0/go.mod h1:5uvzRHogNm1qhJdZ0kNoJNsY1szf9NkHm3l2MbIRV8s=
1313
github.com/aperturerobotics/logrus v1.9.4-0.20240119050608-13332fb58195 h1:uyeD1J23j/kFiCFO7rx+GQA4tCqOEy3IJyMK4f6vamE=
@@ -22,8 +22,8 @@ github.com/aperturerobotics/timestamp v0.8.2 h1:+HA/uI9ZGz8qqim+kkXqz3cijR8kMcQ4
2222
github.com/aperturerobotics/timestamp v0.8.2/go.mod h1:nrwzlUGvxs244CIBjDWHZ8qRudqk8m/SQ5n5GKXaFVw=
2323
github.com/aperturerobotics/ts-proto-common-types v0.20.2 h1:xFy3ErasS5PNWV0ABdlJxqfUsZGL2OLlc0Kio5aIm2s=
2424
github.com/aperturerobotics/ts-proto-common-types v0.20.2/go.mod h1:TgjsdPI5YvNF1iewbvCPmEnVkV8WVP1AyZxiOc9SEbo=
25-
github.com/aperturerobotics/util v1.15.3 h1:xZ/kn2kpuERrP/4yjGReI+unHom2R0Eq0UDVfQF/wYI=
26-
github.com/aperturerobotics/util v1.15.3/go.mod h1:lHjziUGIvJ8EVJMVhVkTF4PTuL3M/FmAFSt8PoT8Wdw=
25+
github.com/aperturerobotics/util v1.16.0 h1:w0XOUw8pT+Dg/Q9eTXO9ZFALLIalV0AK7Ba8Nf8i1XU=
26+
github.com/aperturerobotics/util v1.16.0/go.mod h1:aMfWWor4v05bs0dTekucKSjVkmnTxKE6UPs3rCe84YM=
2727
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
2828
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
2929
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=

0 commit comments

Comments
 (0)