Skip to content

Commit e88cc8f

Browse files
committed
fix linter
1 parent dbae7a5 commit e88cc8f

File tree

26 files changed

+74
-112
lines changed

26 files changed

+74
-112
lines changed

.golangci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
linters:
2+
enable:
3+
- errcheck
4+
- gofmt
5+
- govet
6+
- ineffassign
7+
- unconvert
8+
- staticcheck
9+
- gocyclo
10+
enable-all: false
11+
linters-settings:
12+
gocyclo:
13+
# Minimal code complexity to report.
14+
# Default: 30 (but we recommend 10-20)
15+
min-complexity: 100
16+
run:
17+
timeout: 20m

pkg/Makefile

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,21 @@ GOPATH := $(shell go env GOPATH)
33

44
all: build
55

6-
getdeps:
7-
@echo "Installing golint" && go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.0
8-
@echo "Installing gocyclo" && go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
9-
@echo "Installing deadcode" && go install github.com/remyoudompheng/go-misc/deadcode@latest
10-
@echo "Installing misspell" && go install github.com/client9/misspell/cmd/misspell@latest
11-
@echo "Installing ineffassign" && go install github.com/gordonklaus/ineffassign@latest
12-
@echo "Installing staticcheck" && go install honnef.co/go/tools/cmd/staticcheck@latest
13-
14-
verifiers: vet fmt lint cyclo spelling static #deadcode
15-
16-
vet:
17-
@echo "Running $@"
18-
@go vet -atomic -bool -copylocks -nilfunc -printf -rangeloops -unreachable -unsafeptr -unusedresult ./...
6+
all: getdeps test
197

20-
fmt:
21-
@echo "Running $@"
22-
@gofmt -d .
8+
getdeps:
9+
@echo "Installing golangci-lint" && go get github.com/golangci/golangci-lint/cmd/golangci-lint && go install github.com/golangci/golangci-lint/cmd/golangci-lint
10+
go mod tidy
2311

2412
lint:
2513
@echo "Running $@"
26-
@${GOPATH}/bin/golangci-lint run
27-
28-
ineffassign:
29-
@echo "Running $@"
30-
@${GOPATH}/bin/ineffassign .
31-
32-
cyclo:
33-
@echo "Running $@"
34-
@${GOPATH}/bin/gocyclo -over 100 .
35-
36-
deadcode:
37-
@echo "Running $@"
38-
@${GOPATH}/bin/deadcode -test $(shell go list ./...) || true
39-
40-
spelling:
41-
@${GOPATH}/bin/misspell -i "monitord,forumla,etherent" -error `find .`
42-
43-
static:
44-
@${GOPATH}/bin/staticcheck -- ./...
14+
@${GOPATH}/bin/golangci-lint run -c ../.golangci.yml
4515

4616
check: test
47-
test: verifiers build
17+
test: lint build
4818
go test -vet=off -v $(shell go list ./... | grep -Ev "stubs|network" )
4919

50-
testrace: verifiers build
20+
testrace: lint build
5121
go test -vet=off -v $(shell go list ./... | grep -Ev "stubs|network" )
5222

5323
generate:

pkg/container/container.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ func (c *Module) start(ns, id string) error {
426426

427427
ctx := namespaces.WithNamespace(context.Background(), ns)
428428

429-
container, err := client.LoadContainer(ctx, string(id))
429+
container, err := client.LoadContainer(ctx, id)
430430
if err != nil {
431431
return err
432432
}
@@ -615,7 +615,7 @@ func (c *Module) Delete(ns string, id pkg.ContainerID) error {
615615
_ = task.Kill(ctx, syscall.SIGTERM)
616616
select {
617617
case <-exitC:
618-
case <-time.After(time.Duration(shutdownTimeout)):
618+
case <-time.After(shutdownTimeout):
619619
log.Debug().Str("id", string(id)).Int("signal", int(syscall.SIGKILL)).Msg("sending signal")
620620
_ = task.Kill(ctx, syscall.SIGKILL)
621621
select {

pkg/container/stats/stats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func Monitor(addr string, ns string, id string, backend io.WriteCloser) error {
4646

4747
ctx := namespaces.WithNamespace(context.Background(), ns)
4848

49-
container, err := client.LoadContainer(ctx, string(id))
49+
container, err := client.LoadContainer(ctx, id)
5050
if err != nil {
5151
log.Error().Err(err).Msg("metric container")
5252
return err

pkg/crypto/crypto_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ func TestPyNACLCompatibilityEncryption(t *testing.T) {
7777
sk := ed25519.NewKeyFromSeed(seed)
7878

7979
chiper := ""
80-
fmt.Sscanf("0bfe9e3b9ce17fe6d570b165ea2a01034326b8c81d5f2c5384c8fe886552f074ec43017465598c4f5a857b495b445be46c3df48d14878bd0b1b907", "%x", &chiper)
80+
_, err := fmt.Sscanf("0bfe9e3b9ce17fe6d570b165ea2a01034326b8c81d5f2c5384c8fe886552f074ec43017465598c4f5a857b495b445be46c3df48d14878bd0b1b907", "%x", &chiper)
81+
require.NoError(t, err)
8182

8283
decrypted, err := Decrypt([]byte(chiper), sk)
8384
require.NoError(t, err)

pkg/flist/cleanup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (f *flistModule) cleanCache(now time.Time, age time.Duration) error {
5959

6060
if sys, ok := sys.(*syscall.Stat_t); ok {
6161
// int64 cast required for arm32 targets
62-
atime := time.Unix(int64(sys.Atim.Sec), int64(sys.Atim.Nsec))
62+
atime := time.Unix(sys.Atim.Sec, sys.Atim.Nsec)
6363

6464
if now.Sub(atime) > age {
6565
if err := os.Remove(path); err != nil {

pkg/gateway/gateway.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ func (g *gatewayModule) configPath(name string) string {
532532

533533
func (g *gatewayModule) validateNameContract(name string, twinID uint32) error {
534534

535-
contractID, subErr := g.substrateGateway.GetContractIDByNameRegistration(context.Background(), string(name))
535+
contractID, subErr := g.substrateGateway.GetContractIDByNameRegistration(context.Background(), name)
536536
if subErr.IsCode(pkg.CodeNotFound) {
537537
return ErrContractNotReserved
538538
}
@@ -633,7 +633,7 @@ func (g *gatewayModule) setupRouting(ctx context.Context, wlID string, fqdn stri
633633

634634
backend := config.Backends[0]
635635

636-
if err := zos.Backend(backend).Valid(config.TLSPassthrough); err != nil {
636+
if err := backend.Valid(config.TLSPassthrough); err != nil {
637637
return errors.Wrapf(err, "failed to validate backend '%s'", backend)
638638
}
639639

pkg/gridtypes/id.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (i WorkloadID) Unique(n string) string {
7171
b = b[:13]
7272
}
7373

74-
return string(b)
74+
return b
7575
}
7676

7777
// IsValidName validates workload name

pkg/gridtypes/workload_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestTimestamp(t *testing.T) {
2121
exp, err := json.Marshal(n)
2222
require.NoError(err)
2323

24-
err = json.Unmarshal([]byte(exp), &v)
24+
err = json.Unmarshal(exp, &v)
2525
require.NoError(err)
2626

2727
require.Equal(Timestamp(n.Unix()), v)

pkg/gridtypes/zos/network.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func NetworkID(twin uint32, network gridtypes.Name) NetID {
3232
if len(b) > 13 {
3333
b = b[:13]
3434
}
35-
return NetID(string(b))
35+
return NetID(b)
3636
}
3737

3838
func NetworkIDFromWorkloadID(wl gridtypes.WorkloadID) (NetID, error) {

pkg/network/mycelium/mycelium.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (s *MyceliumServer) InspectMycelium() (inspection MyceliumInspection, err e
183183

184184
// IP return the address in the 400::/7 subnet allocated by mycelium
185185
func (m *MyceliumInspection) IP() net.IP {
186-
return net.IP(m.Address)
186+
return m.Address
187187
}
188188

189189
// Subnet return the 400::/64 subnet allocated by mycelium

pkg/network/network_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ func TestKeys(t *testing.T) {
3030
strEncrypted := fmt.Sprintf("%x", encrypted)
3131

3232
strDecrypted := ""
33-
fmt.Sscanf(strEncrypted, "%x", &strDecrypted)
33+
_, err = fmt.Sscanf(strEncrypted, "%x", &strDecrypted)
34+
require.NoError(t, err)
3435

3536
decrypted, err := crypto.Decrypt([]byte(strDecrypted), sk)
3637
require.NoError(t, err)

pkg/network/networker.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ func (n *networker) SetupPrivTap(networkID pkg.NetID, name string) (ifc string,
360360
}
361361

362362
func (n *networker) TapExists(name string) (bool, error) {
363-
log.Info().Str("tap-name", string(name)).Msg("Checking if tap interface exists")
363+
log.Info().Str("tap-name", name).Msg("Checking if tap interface exists")
364364

365365
tapIface, err := tapName(name)
366366
if err != nil {
@@ -372,7 +372,7 @@ func (n *networker) TapExists(name string) (bool, error) {
372372

373373
// RemoveTap in the network resource.
374374
func (n *networker) RemoveTap(name string) error {
375-
log.Info().Str("tap-name", string(name)).Msg("Removing tap interface")
375+
log.Info().Str("tap-name", name).Msg("Removing tap interface")
376376

377377
tapIface, err := tapName(name)
378378
if err != nil {
@@ -390,7 +390,7 @@ func (n *networker) PublicIPv4Support() bool {
390390
// reservation id. It is hooked to the public bridge. The name of the tap
391391
// interface is returned
392392
func (n *networker) SetupPubTap(name string) (string, error) {
393-
log.Info().Str("pubtap-name", string(name)).Msg("Setting up public tap interface")
393+
log.Info().Str("pubtap-name", name).Msg("Setting up public tap interface")
394394

395395
if !n.ndmz.SupportsPubIPv4() {
396396
return "", errors.New("can't create public tap on this node")
@@ -408,7 +408,7 @@ func (n *networker) SetupPubTap(name string) (string, error) {
408408

409409
// SetupMyceliumTap creates a new mycelium tap device attached to this network resource with deterministic IP address
410410
func (n *networker) SetupMyceliumTap(name string, netID zos.NetID, config zos.MyceliumIP) (tap pkg.PlanetaryTap, err error) {
411-
log.Info().Str("tap-name", string(name)).Msg("Setting up mycelium tap interface")
411+
log.Info().Str("tap-name", name).Msg("Setting up mycelium tap interface")
412412

413413
network, err := n.networkOf(netID)
414414
if err != nil {
@@ -452,7 +452,7 @@ func (n *networker) SetupMyceliumTap(name string, netID zos.NetID, config zos.My
452452

453453
// SetupYggTap sets up a tap device in the host namespace for the yggdrasil ip
454454
func (n *networker) SetupYggTap(name string) (tap pkg.PlanetaryTap, err error) {
455-
log.Info().Str("tap-name", string(name)).Msg("Setting up yggdrasil tap interface")
455+
log.Info().Str("tap-name", name).Msg("Setting up yggdrasil tap interface")
456456

457457
tapIface, err := tapName(name)
458458
if err != nil {
@@ -486,7 +486,7 @@ func (n *networker) SetupYggTap(name string) (tap pkg.PlanetaryTap, err error) {
486486

487487
// PubTapExists checks if the tap device for the public network exists already
488488
func (n *networker) PubTapExists(name string) (bool, error) {
489-
log.Info().Str("pubtap-name", string(name)).Msg("Checking if public tap interface exists")
489+
log.Info().Str("pubtap-name", name).Msg("Checking if public tap interface exists")
490490

491491
tapIface, err := pubTapName(name)
492492
if err != nil {
@@ -499,7 +499,7 @@ func (n *networker) PubTapExists(name string) (bool, error) {
499499
// RemovePubTap removes the public tap device from the host namespace
500500
// of the networkID
501501
func (n *networker) RemovePubTap(name string) error {
502-
log.Info().Str("pubtap-name", string(name)).Msg("Removing public tap interface")
502+
log.Info().Str("pubtap-name", name).Msg("Removing public tap interface")
503503

504504
tapIface, err := pubTapName(name)
505505
if err != nil {
@@ -660,7 +660,7 @@ func (n *networker) RemovePubIPFilter(filterName string) error {
660660
// DisconnectPubTap disconnects the public tap from the network. The interface
661661
// itself is not removed and will need to be cleaned up later
662662
func (n *networker) DisconnectPubTap(name string) error {
663-
log.Info().Str("pubtap-name", string(name)).Msg("Disconnecting public tap interface")
663+
log.Info().Str("pubtap-name", name).Msg("Disconnecting public tap interface")
664664
tapIfaceName, err := pubTapName(name)
665665
if err != nil {
666666
return errors.Wrap(err, "could not get network namespace tap device name")

pkg/network/nr/net_resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ func (nr *NetResource) wgPeers() ([]*wireguard.Peer, error) {
644644
}
645645

646646
wgPeer := &wireguard.Peer{
647-
PublicKey: string(peer.WGPublicKey),
647+
PublicKey: peer.WGPublicKey,
648648
AllowedIPs: allowedIPs,
649649
Endpoint: peer.Endpoint,
650650
}

pkg/perf/iperf/iperf_task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (t *IperfTest) runIperfTest(ctx context.Context, clientIP string, tcp bool)
154154
operation := func() error {
155155
res := runIperfCommand(ctx, opts)
156156
if res.Error == errServerBusy {
157-
return fmt.Errorf(errServerBusy)
157+
return errors.New(errServerBusy)
158158
}
159159

160160
report = res

pkg/perf/publicip/publicip_task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func isLeastValidNode(ctx context.Context, farmID uint32, substrateGateway *stub
207207
}
208208

209209
for _, node := range nodes {
210-
if node.NodeID >= uint32(nodeID) {
210+
if node.NodeID >= nodeID {
211211
continue
212212
}
213213
n, err := substrateGateway.GetNode(ctx, node.NodeID)

pkg/power/ethtool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func valueOfFlag(output []byte, flag Flag) (string, error) {
5757
if len(parts) != 2 {
5858
return "", fmt.Errorf("invalid ethtool output format (%s)", line)
5959
}
60-
return strings.TrimSpace(string(parts[1])), nil
60+
return strings.TrimSpace(parts[1]), nil
6161
}
6262

6363
return "", ErrFlagNotFound

pkg/provision/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (s *substrateTwins) GetKey(id uint32) ([]byte, error) {
4040

4141
key := user.Account.PublicKey()
4242
s.mem.Add(id, key)
43-
return []byte(key), nil
43+
return key, nil
4444
}
4545

4646
type substrateAdmins struct {

pkg/provision/engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ func (e *NativeEngine) validate(ctx context.Context, dl *gridtypes.Deployment, n
572572
return ctx, fmt.Errorf("substrate is not configured in engine")
573573
}
574574

575-
contract, subErr := e.substrateGateway.GetContract(ctx, uint64(dl.ContractID))
575+
contract, subErr := e.substrateGateway.GetContract(ctx, dl.ContractID)
576576
if subErr.IsError() {
577577
return nil, errors.Wrap(subErr.Err, "failed to get deployment contract")
578578
}

pkg/provision/storage.fs/storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ func (s *Fs) byTwin(twin uint32) ([]uint64, error) {
283283
continue
284284
}
285285

286-
ids = append(ids, uint64(id))
286+
ids = append(ids, id)
287287
}
288288

289289
return ids, nil

pkg/qsfsd/cleanup.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ func (q *QSFS) checkDeadQSFSs(ctx context.Context, state *failedQSFSState) error
5959
}
6060
for _, path := range paths {
6161
wlID := filepath.Base(path)
62-
metrics, err := q.qsfsMetrics(ctx, string(wlID))
62+
metrics, err := q.qsfsMetrics(ctx, wlID)
6363
if err != nil {
64-
log.Err(err).Str("id", string(wlID)).Msg("couldn't get qsfs metrics")
65-
state.metricsFailureCount[string(wlID)] += 1
66-
if state.metricsFailureCount[string(wlID)] >= 10 {
64+
log.Err(err).Str("id", wlID).Msg("couldn't get qsfs metrics")
65+
state.metricsFailureCount[wlID] += 1
66+
if state.metricsFailureCount[wlID] >= 10 {
6767
q.Unmount(wlID)
6868
state.delete(wlID)
6969
}

pkg/qsfsd/qsfs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (q *QSFS) Mount(wlID string, cfg zos.QuantumSafeFS) (info pkg.QSFSInfo, err
169169
if containerErr != nil {
170170
log.Error().Err(containerErr).Msg("Failed to read container logs")
171171
}
172-
err = errors.Wrapf(lerr, fmt.Sprintf("Container Logs:\n%s", logs))
172+
err = errors.Wrapf(lerr, "Container Logs:\n%s", logs)
173173
return
174174
}
175175
log.Debug().Str("duration", time.Since(t).String()).Msg("waiting for qsfs deployment took")

pkg/storage/storage_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ func TestCacheResize(t *testing.T) {
416416
Excl: 1,
417417
},
418418
}
419-
vol.On("Limit", uint64(cacheSize)).Return(nil)
419+
vol.On("Limit", cacheSize).Return(nil)
420420
err := m.checkAndResizeCache(&vol, cacheSize)
421421
require.NoError(t, err)
422422

@@ -444,7 +444,7 @@ func TestCacheResize(t *testing.T) {
444444
Excl: 0, // no files
445445
},
446446
}
447-
vol.On("Limit", uint64(cacheSize)).Return(nil)
447+
vol.On("Limit", cacheSize).Return(nil)
448448
err = m.checkAndResizeCache(&vol, cacheSize)
449449
require.NoError(t, err)
450450

@@ -468,7 +468,7 @@ func TestCacheResize(t *testing.T) {
468468
Excl: 91,
469469
},
470470
}
471-
vol.On("Limit", uint64(100+cacheSize)).Return(nil)
471+
vol.On("Limit", 100+cacheSize).Return(nil)
472472
err = m.checkAndResizeCache(&vol, cacheSize)
473473
require.NoError(t, err)
474474

pkg/vm/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func (m *Module) withLogs(path string, err error) error {
322322
return errors.Wrapf(err, "failed to tail machine logs: %s", tailErr)
323323
}
324324

325-
return errors.Wrapf(err, string(logs))
325+
return errors.Wrap(err, logs)
326326
}
327327

328328
func (m *Module) checkDevicesUsed(devices []string) error {

0 commit comments

Comments
 (0)