Skip to content

Commit

Permalink
refactor: enforce stricter linter settings
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Stewart <[email protected]>
  • Loading branch information
paralin committed Apr 2, 2024
1 parent b3853e2 commit 30b1c5f
Show file tree
Hide file tree
Showing 27 changed files with 206 additions and 338 deletions.
62 changes: 62 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,67 @@
linters:
enable:
- depguard
- goimports
- gosec
- gosimple
- govet
- importas
- ineffassign
- misspell
- revive
- staticcheck
- typecheck
- unconvert
- unused

disable:
- errcheck

run:
concurrency: 4
modules-download-mode: vendor

skip-dirs:
- hack

linters-settings:
staticcheck:
checks:
- all
- '-SA1012' # Allow passing nil contexts.

importas:
# Do not allow unaliased imports of aliased packages.
no-unaliased: true

maligned:
suggest-new: true

depguard:
rules:
main:
deny:
- pkg: io/ioutil
desc: The io/ioutil package has been deprecated, see https://go.dev/doc/go1.16#ioutil
- pkg: "github.com/stretchr/testify/assert"
desc: Use "gotest.tools/v3/assert" instead
- pkg: "github.com/stretchr/testify/require"
desc: Use "gotest.tools/v3/assert" instead
- pkg: "github.com/stretchr/testify/suite"
desc: Do not use

revive:
rules:
- name: package-comments
disabled: true

gosec:
excludes:
- G306 # Allow WriteFile permissions to be 0644.

issues:
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0

# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0
56 changes: 19 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ PROTOWRAP=hack/bin/protowrap
PROTOC_GEN_GO=hack/bin/protoc-gen-go
PROTOC_GEN_STARPC=hack/bin/protoc-gen-go-starpc
PROTOC_GEN_VTPROTO=hack/bin/protoc-gen-go-vtproto
PROTOC_GEN_GO_DRPC=hack/bin/protoc-gen-go-drpc
GOIMPORTS=hack/bin/goimports
GOFUMPT=hack/bin/gofumpt
GOLANGCI_LINT=hack/bin/golangci-lint
GO_MOD_OUTDATED=hack/bin/go-mod-outdated
WASMSERVE=hack/bin/wasmserve
GORELEASER=hack/bin/goreleaser
GOLIST=go list -f "{{ .Dir }}" -m

export GO111MODULE=on
undefine GOARCH
undefine GOOS
undefine GOARCH

all:

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

$(PROTOC_GEN_GO_DRPC):
cd ./hack; \
go build -v \
-o ./bin/protoc-gen-go-drpc \
storj.io/drpc/cmd/protoc-gen-go-drpc

$(PROTOC_GEN_STARPC):
cd ./hack; \
go build -v \
Expand All @@ -52,6 +44,12 @@ $(GOIMPORTS):
-o ./bin/goimports \
golang.org/x/tools/cmd/goimports

$(GOFUMPT):
cd ./hack; \
go build -v \
-o ./bin/gofumpt \
mvdan.cc/gofumpt

$(PROTOWRAP):
cd ./hack; \
go build -v \
Expand All @@ -70,20 +68,8 @@ $(GO_MOD_OUTDATED):
-o ./bin/go-mod-outdated \
github.com/psampaz/go-mod-outdated

$(WASMSERVE):
cd ./hack; \
go build -v \
-o ./bin/wasmserve \
github.com/hajimehoshi/wasmserve

$(GORELEASER):
cd ./hack; \
go build -v \
-o ./bin/goreleaser \
github.com/goreleaser/goreleaser

.PHONY: gengo
gengo: $(GOIMPORTS) $(PROTOWRAP) $(PROTOC_GEN_GO) $(PROTOC_GEN_VTPROTO) $(PROTOC_GEN_GO_DRPC) $(PROTOC_GEN_STARPC)
gengo: vendor $(GOIMPORTS) $(PROTOWRAP) $(PROTOC_GEN_GO) $(PROTOC_GEN_VTPROTO) $(PROTOC_GEN_STARPC)
shopt -s globstar; \
set -eo pipefail; \
export PROJECT=$$(go list -m); \
Expand All @@ -96,10 +82,6 @@ gengo: $(GOIMPORTS) $(PROTOWRAP) $(PROTOC_GEN_GO) $(PROTOC_GEN_VTPROTO) $(PROTOC
--go_out=$$(pwd)/vendor \
--go-vtproto_out=$$(pwd)/vendor \
--go-vtproto_opt=features=marshal+unmarshal+size+equal+clone \
--go-drpc_out=$$(pwd)/vendor \
--go-drpc_opt=json=false \
--go-drpc_opt=protolib=github.com/golang/protobuf/proto \
--go-drpc_opt=protolib=github.com/planetscale/vtprotobuf/codec/drpc \
--go-starpc_out=$$(pwd)/vendor \
--proto_path $$(pwd)/vendor \
--print_structure \
Expand All @@ -116,7 +98,7 @@ node_modules:
yarn install

.PHONY: gents
gents: $(PROTOWRAP) node_modules
gents: vendor $(PROTOWRAP) node_modules
shopt -s globstar; \
set -eo pipefail; \
export PROJECT=$$(go list -m); \
Expand Down Expand Up @@ -146,10 +128,10 @@ gents: $(PROTOWRAP) node_modules
xargs printf -- \
"$$(pwd)/vendor/$${PROJECT}/%s "); \
rm $$(pwd)/vendor/$${PROJECT} || true
npm run format
npm run format:js

.PHONY: genproto
genproto: gengo gents
genproto: gents gengo

.PHONY: gen
gen: genproto
Expand All @@ -170,15 +152,15 @@ lint: $(GOLANGCI_LINT)
fix: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run --fix --timeout=10m

.PHONY: serve-example
serve-example: $(WASMSERVE)
$(WASMSERVE) -http ":8090" ./examples/websocket-browser-link/browser
.PHONY: format
format: $(GOFUMPT) $(GOIMPORTS)
$(GOIMPORTS) -w ./
$(GOFUMPT) -w ./

.PHONY: test
test:
go test -v ./...

.PHONY: release
release: $(GORELEASER)
$(GORELEASER) release --clean

.PHONY: serve-example
serve-example: $(WASMSERVE)
$(WASMSERVE) -http ":8090" ./examples/websocket-browser-link/browser
2 changes: 1 addition & 1 deletion cli/daemonflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (a *DaemonArgs) ApplyToConfigSet(confSet configset.ConfigSet, overwrite boo
}
if len(a.EstablishPeers.Value()) != 0 {
establishConf := &link_establish_controller.Config{
PeerIds: []string(a.EstablishPeers.Value()),
PeerIds: a.EstablishPeers.Value(),
}
if err := establishConf.Validate(); err != nil {
return errors.Wrap(err, "establish-peers")
Expand Down
24 changes: 19 additions & 5 deletions cmd/bifrost/cmd_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"net/http"
"os"
"runtime"
"time"

"net/http/pprof"

bcli "github.com/aperturerobotics/bifrost/cli"
"github.com/aperturerobotics/bifrost/daemon"
Expand All @@ -26,10 +29,6 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"

// _ enables the profiling endpoints

_ "net/http/pprof"
)

var daemonFlags struct {
Expand Down Expand Up @@ -235,7 +234,22 @@ func runDaemon(c *cli.Context) error {
runtime.SetMutexProfileFraction(1)
go func() {
le.Debugf("profiling listener running: %s", daemonFlags.ProfListen)
err := http.ListenAndServe(daemonFlags.ProfListen, nil)
mux := http.NewServeMux()

// Register pprof handlers
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
// Manually add support for paths linked to by index page at /debug/pprof/
mux.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
mux.Handle("/debug/pprof/heap", pprof.Handler("heap"))
mux.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
mux.Handle("/debug/pprof/block", pprof.Handler("block"))

server := &http.Server{Addr: daemonFlags.ProfListen, Handler: mux, ReadHeaderTimeout: time.Second * 10}
err := server.ListenAndServe()
le.WithError(err).Warn("profiling listener exited")
}()
}
Expand Down
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
module github.com/aperturerobotics/bifrost

go 1.21
go 1.22

toolchain go1.22.1

require (
github.com/aperturerobotics/controllerbus v0.36.8 // latest
github.com/aperturerobotics/controllerbus v0.37.0 // latest
github.com/aperturerobotics/entitygraph v0.7.0
github.com/aperturerobotics/starpc v0.27.3 // latest
github.com/aperturerobotics/timestamp v0.8.2
github.com/aperturerobotics/ts-proto-common-types v0.20.2 // latest
github.com/aperturerobotics/util v1.15.3 // master
github.com/aperturerobotics/util v1.16.0 // master
)

// aperture: use compatibility forks
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/aperturerobotics/bifrost-nats-client v1.10.1-0.20200831103200-24c3d04
github.com/aperturerobotics/bifrost-nats-client v1.10.1-0.20200831103200-24c3d0464e58/go.mod h1:ougcjYEZDYV8pVtaNbA5sgYDukkYHyKtSsW/T3B13j0=
github.com/aperturerobotics/bifrost-nats-server/v2 v2.1.8-0.20221228081037-b7c2df0c151f h1:bmScByQNGDPPy9T+zdwu816XaCbFtD5UDyqZMRiHJ80=
github.com/aperturerobotics/bifrost-nats-server/v2 v2.1.8-0.20221228081037-b7c2df0c151f/go.mod h1:kIcZtLpq4UIZzOqduYLm1mYU1nuMBtN6XuDCtQ21QT8=
github.com/aperturerobotics/controllerbus v0.36.8 h1:s2345jsYjrhXUzfWUJDkwIgLmeX456U4E0jg+ktafKA=
github.com/aperturerobotics/controllerbus v0.36.8/go.mod h1:Z+jw8kAx5+aLQYiugd1OnBJIkUaDX4RdQkDleozw3i0=
github.com/aperturerobotics/controllerbus v0.37.0 h1:0Jut71UFBNeQywGy6S+esdtsGSMn6SvSpj3qlu1bwP4=
github.com/aperturerobotics/controllerbus v0.37.0/go.mod h1:NJITG4lLK3lDI+GdhxjG9dyA9kxOLJzjajkNRs5hctc=
github.com/aperturerobotics/entitygraph v0.7.0 h1:VqLRJL09a5K+Wm776TVgYNcPWVSTAg4z2WWqKBJ3WTA=
github.com/aperturerobotics/entitygraph v0.7.0/go.mod h1:5uvzRHogNm1qhJdZ0kNoJNsY1szf9NkHm3l2MbIRV8s=
github.com/aperturerobotics/logrus v1.9.4-0.20240119050608-13332fb58195 h1:uyeD1J23j/kFiCFO7rx+GQA4tCqOEy3IJyMK4f6vamE=
Expand All @@ -22,8 +22,8 @@ github.com/aperturerobotics/timestamp v0.8.2 h1:+HA/uI9ZGz8qqim+kkXqz3cijR8kMcQ4
github.com/aperturerobotics/timestamp v0.8.2/go.mod h1:nrwzlUGvxs244CIBjDWHZ8qRudqk8m/SQ5n5GKXaFVw=
github.com/aperturerobotics/ts-proto-common-types v0.20.2 h1:xFy3ErasS5PNWV0ABdlJxqfUsZGL2OLlc0Kio5aIm2s=
github.com/aperturerobotics/ts-proto-common-types v0.20.2/go.mod h1:TgjsdPI5YvNF1iewbvCPmEnVkV8WVP1AyZxiOc9SEbo=
github.com/aperturerobotics/util v1.15.3 h1:xZ/kn2kpuERrP/4yjGReI+unHom2R0Eq0UDVfQF/wYI=
github.com/aperturerobotics/util v1.15.3/go.mod h1:lHjziUGIvJ8EVJMVhVkTF4PTuL3M/FmAFSt8PoT8Wdw=
github.com/aperturerobotics/util v1.16.0 h1:w0XOUw8pT+Dg/Q9eTXO9ZFALLIalV0AK7Ba8Nf8i1XU=
github.com/aperturerobotics/util v1.16.0/go.mod h1:aMfWWor4v05bs0dTekucKSjVkmnTxKE6UPs3rCe84YM=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
Expand Down
Loading

0 comments on commit 30b1c5f

Please sign in to comment.