Skip to content

Commit 38d6f57

Browse files
authored
chore: Enable golangci-lint (#7)
2 parents e66190d + 97ce785 commit 38d6f57

22 files changed

+89
-56
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
name: golangci-lint
3+
on:
4+
push:
5+
paths:
6+
- "go.sum"
7+
- "go.mod"
8+
- "**.go"
9+
- ".github/workflows/golangci-lint.yml"
10+
- ".golangci.yml"
11+
pull_request:
12+
13+
permissions: # added using https://github.com/step-security/secure-repo
14+
contents: read
15+
16+
jobs:
17+
golangci:
18+
permissions:
19+
contents: read # for actions/checkout to fetch code
20+
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
21+
name: lint
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26+
- name: Install Go
27+
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
28+
with:
29+
go-version: 1.23.x
30+
- name: Lint
31+
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1
32+
with:
33+
args: --verbose
34+
version: v1.62.0

.golangci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
linters:
3+
enable:
4+
# - goimports
5+
# - misspell
6+
# - revive
7+
8+
issues:
9+
exclude-rules:
10+
- path: _test.go
11+
linters:
12+
- errcheck

cloud.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func runWebsocketClient() error {
150150
if err != nil {
151151
return err
152152
}
153-
defer c.CloseNow()
153+
defer c.CloseNow() //nolint:errcheck
154154
cloudLogger.Infof("websocket connected to %s", wsURL)
155155
runCtx, cancelRun := context.WithCancel(context.Background())
156156
defer cancelRun()

cmd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
import (
4-
"kvm"
4+
"github.com/jetkvm/kvm"
55
)
66

77
func main() {

config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package kvm
33
import (
44
"encoding/json"
55
"fmt"
6-
"kvm/internal/usbgadget"
76
"os"
87
"sync"
8+
9+
"github.com/jetkvm/kvm/internal/usbgadget"
910
)
1011

1112
type WakeOnLanDevice struct {

display.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func startBacklightTickers() {
211211
// Don't start the tickers if the display is switched off.
212212
// Set the display to off if that's the case.
213213
if config.DisplayMaxBrightness == 0 {
214-
setDisplayBrightness(0)
214+
_ = setDisplayBrightness(0)
215215
return
216216
}
217217

@@ -221,7 +221,7 @@ func startBacklightTickers() {
221221
defer dimTicker.Stop()
222222

223223
go func() {
224-
for {
224+
for { //nolint:gosimple
225225
select {
226226
case <-dimTicker.C:
227227
tick_displayDim()
@@ -236,7 +236,7 @@ func startBacklightTickers() {
236236
defer offTicker.Stop()
237237

238238
go func() {
239-
for {
239+
for { //nolint:gosimple
240240
select {
241241
case <-offTicker.C:
242242
tick_displayOff()

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module kvm
1+
module github.com/jetkvm/kvm
22

33
go 1.21.0
44

@@ -15,7 +15,6 @@ require (
1515
github.com/gwatts/rootcerts v0.0.0-20240401182218-3ab9db955caf
1616
github.com/hanwen/go-fuse/v2 v2.5.1
1717
github.com/hashicorp/go-envparse v0.1.0
18-
github.com/openstadia/go-usb-gadget v0.0.0-20231115171102-aebd56bbb965
1918
github.com/pion/logging v0.2.2
2019
github.com/pion/mdns/v2 v2.0.7
2120
github.com/pion/webrtc/v4 v4.0.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
8787
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
8888
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
8989
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
90-
github.com/openstadia/go-usb-gadget v0.0.0-20231115171102-aebd56bbb965 h1:bZGtUfkOl0dqvem8ltx9KCYied0gSlRuDhaZDxgppN4=
91-
github.com/openstadia/go-usb-gadget v0.0.0-20231115171102-aebd56bbb965/go.mod h1:6cAIK2c4O3/yETSrRjmNwsBL3yE4Vcu9M9p/Qwx5+gM=
9290
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
9391
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
9492
github.com/pilebones/go-udev v0.9.0 h1:N1uEO/SxUwtIctc0WLU0t69JeBxIYEYnj8lT/Nabl9Q=

hw.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func extractSerialNumber() (string, error) {
1414
return "", err
1515
}
1616

17-
r, err := regexp.Compile("Serial\\s*:\\s*(\\S+)")
17+
r, err := regexp.Compile(`Serial\s*:\s*(\S+)`)
1818
if err != nil {
1919
return "", fmt.Errorf("failed to compile regex: %w", err)
2020
}
@@ -27,7 +27,7 @@ func extractSerialNumber() (string, error) {
2727
return matches[1], nil
2828
}
2929

30-
func readOtpEntropy() ([]byte, error) {
30+
func readOtpEntropy() ([]byte, error) { //nolint:unused
3131
content, err := os.ReadFile("/sys/bus/nvmem/devices/rockchip-otp0/nvmem")
3232
if err != nil {
3333
return nil, err

jiggler.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import (
66

77
var lastUserInput = time.Now()
88

9-
func resetUserInputTime() {
10-
lastUserInput = time.Now()
11-
}
12-
139
var jigglerEnabled = false
1410

1511
func rpcSetJigglerState(enabled bool) {

jsonrpc.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8-
"kvm/internal/usbgadget"
98
"os"
109
"os/exec"
1110
"path/filepath"
@@ -15,6 +14,8 @@ import (
1514

1615
"github.com/pion/webrtc/v4"
1716
"go.bug.st/serial"
17+
18+
"github.com/jetkvm/kvm/internal/usbgadget"
1819
)
1920

2021
type JSONRPCRequest struct {
@@ -195,8 +196,7 @@ func rpcSetEDID(edid string) error {
195196

196197
// Save EDID to config, allowing it to be restored on reboot.
197198
config.EdidString = edid
198-
SaveConfig()
199-
199+
_ = SaveConfig()
200200
return nil
201201
}
202202

@@ -596,18 +596,18 @@ func rpcSetActiveExtension(extensionId string) error {
596596
return nil
597597
}
598598
if config.ActiveExtension == "atx-power" {
599-
unmountATXControl()
599+
_ = unmountATXControl()
600600
} else if config.ActiveExtension == "dc-power" {
601-
unmountDCControl()
601+
_ = unmountDCControl()
602602
}
603603
config.ActiveExtension = extensionId
604604
if err := SaveConfig(); err != nil {
605605
return fmt.Errorf("failed to save config: %w", err)
606606
}
607607
if extensionId == "atx-power" {
608-
mountATXControl()
608+
_ = mountATXControl()
609609
} else if extensionId == "dc-power" {
610-
mountDCControl()
610+
_ = mountDCControl()
611611
}
612612
return nil
613613
}
@@ -728,7 +728,7 @@ func rpcSetSerialSettings(settings SerialSettings) error {
728728
Parity: parity,
729729
}
730730

731-
port.SetMode(serialPortMode)
731+
_ = port.SetMode(serialPortMode)
732732

733733
return nil
734734
}

log.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ import "github.com/pion/logging"
55
// we use logging framework from pion
66
// ref: https://github.com/pion/webrtc/wiki/Debugging-WebRTC
77
var logger = logging.NewDefaultLoggerFactory().NewLogger("jetkvm")
8-
var usbLogger = logging.NewDefaultLoggerFactory().NewLogger("usb")
98
var cloudLogger = logging.NewDefaultLoggerFactory().NewLogger("cloud")

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func Main() {
4949
time.Sleep(15 * time.Minute)
5050
for {
5151
logger.Debugf("UPDATING - Auto update enabled: %v", config.AutoUpdateEnabled)
52-
if config.AutoUpdateEnabled == false {
52+
if !config.AutoUpdateEnabled {
5353
return
5454
}
5555
if currentSession != nil {

native.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8-
"kvm/resource"
98
"net"
109
"os"
1110
"os/exec"
1211
"sync"
1312
"syscall"
1413
"time"
1514

15+
"github.com/jetkvm/kvm/resource"
16+
1617
"github.com/pion/webrtc/v4/pkg/media"
1718
)
1819

@@ -90,8 +91,8 @@ func WriteCtrlMessage(message []byte) error {
9091
return err
9192
}
9293

93-
var nativeCtrlSocketListener net.Listener
94-
var nativeVideoSocketListener net.Listener
94+
var nativeCtrlSocketListener net.Listener //nolint:unused
95+
var nativeVideoSocketListener net.Listener //nolint:unused
9596

9697
var ctrlClientConnected = make(chan struct{})
9798

network.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func checkNetworkState() {
107107
if newState != networkState {
108108
logger.Info("network state changed")
109109
// restart MDNS
110-
startMDNS()
110+
_ = startMDNS()
111111
networkState = newState
112112
requestDisplayUpdate()
113113
}

ntp.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const (
2020
)
2121

2222
var (
23-
timeSynced = false
2423
timeSyncRetryInterval = 0 * time.Second
2524
defaultNTPServers = []string{
2625
"time.cloudflare.com",
@@ -58,7 +57,6 @@ func TimeSyncLoop() {
5857
continue
5958
}
6059
logger.Infof("Time sync successful, now is: %v, time taken: %v", time.Now(), time.Since(start))
61-
timeSynced = true
6260
time.Sleep(timeSyncInterval) // after the first sync is done
6361
}
6462
}

remote_mount.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (w *WebRTCDiskReader) Read(ctx context.Context, offset int64, size int64) (
4949
if err != nil {
5050
return nil, err
5151
}
52-
buf := make([]byte, 0)
52+
var buf []byte
5353
for {
5454
select {
5555
case data := <-diskReadChan:

serial.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ const serialPortPath = "/dev/ttyS3"
1616
var port serial.Port
1717

1818
func mountATXControl() error {
19-
port.SetMode(defaultMode)
19+
_ = port.SetMode(defaultMode)
2020
go runATXControl()
2121

2222
return nil
2323
}
2424

2525
func unmountATXControl() error {
26-
reopenSerialPort()
26+
_ = reopenSerialPort()
2727
return nil
2828
}
2929

@@ -122,13 +122,13 @@ func pressATXResetButton(duration time.Duration) error {
122122
}
123123

124124
func mountDCControl() error {
125-
port.SetMode(defaultMode)
125+
_ = port.SetMode(defaultMode)
126126
go runDCControl()
127127
return nil
128128
}
129129

130130
func unmountDCControl() error {
131-
reopenSerialPort()
131+
_ = reopenSerialPort()
132132
return nil
133133
}
134134

@@ -212,11 +212,11 @@ var defaultMode = &serial.Mode{
212212
}
213213

214214
func initSerialPort() {
215-
reopenSerialPort()
215+
_ = reopenSerialPort()
216216
if config.ActiveExtension == "atx-power" {
217-
mountATXControl()
217+
_ = mountATXControl()
218218
} else if config.ActiveExtension == "dc-power" {
219-
mountDCControl()
219+
_ = mountDCControl()
220220
}
221221
}
222222

terminal.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ func handleTerminalChannel(d *webrtc.DataChannel) {
5555
var size TerminalSize
5656
err := json.Unmarshal([]byte(msg.Data), &size)
5757
if err == nil {
58-
pty.Setsize(ptmx, &pty.Winsize{
58+
err = pty.Setsize(ptmx, &pty.Winsize{
5959
Rows: uint16(size.Rows),
6060
Cols: uint16(size.Cols),
6161
})
62-
return
62+
if err == nil {
63+
return
64+
}
6365
}
6466
logger.Errorf("Failed to parse terminal size: %v", err)
6567
}
@@ -74,7 +76,7 @@ func handleTerminalChannel(d *webrtc.DataChannel) {
7476
ptmx.Close()
7577
}
7678
if cmd != nil && cmd.Process != nil {
77-
cmd.Process.Kill()
79+
_ = cmd.Process.Kill()
7880
}
7981
})
8082
}

usb.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package kvm
22

33
import (
4-
"kvm/internal/usbgadget"
4+
"github.com/jetkvm/kvm/internal/usbgadget"
55
"time"
66
)
77

@@ -37,10 +37,6 @@ func rpcWheelReport(wheelY int8) error {
3737
return gadget.AbsMouseWheelReport(wheelY)
3838
}
3939

40-
func rpcRelMouseReport(mx, my int8, buttons uint8) error {
41-
return gadget.RelMouseReport(mx, my, buttons)
42-
}
43-
4440
var usbState = "unknown"
4541

4642
func rpcGetUSBState() (state string) {

0 commit comments

Comments
 (0)