Skip to content

Commit a469ff6

Browse files
committed
ci: use golangci-lint v2, fix issues
1 parent 753128c commit a469ff6

8 files changed

Lines changed: 35 additions & 29 deletions

File tree

.github/workflows/build.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ jobs:
99
name: Tests
1010
runs-on: ubuntu-latest
1111
steps:
12-
13-
- name: Set up Go 1.x
14-
uses: actions/setup-go@v2
12+
- uses: actions/setup-go@v5
1513
with:
16-
go-version: ^1.24
17-
id: go
14+
go-version: stable
1815

19-
- name: Check out code into the Go module directory
20-
uses: actions/checkout@v2
16+
- uses: actions/checkout@v4
2117

2218
- name: Get go-acc
2319
run: go install github.com/ory/go-acc@latest

.github/workflows/golangci-lint.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ jobs:
99
name: lint
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v2
12+
- uses: actions/checkout@v4
13+
1314
- name: golangci-lint
14-
uses: golangci/golangci-lint-action@v2
15+
uses: golangci/golangci-lint-action@v8
1516
with:
16-
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
17-
version: v1.30
17+
version: v2.1

.golangci.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
issues:
2-
# Excluding configuration per-path, per-linter, per-text and per-source
3-
exclude-rules:
4-
# Exclude some linters from running on tests files.
5-
- path: \.go
6-
linters:
7-
- errcheck
1+
version: "2"
2+
3+
linters:
4+
exclusions:
5+
generated: lax
6+
presets:
7+
- comments
8+
- common-false-positives
9+
- legacy
10+
- std-error-handling
11+
12+
formatters:
13+
exclusions:
14+
generated: lax

cmd/pingnet/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func main() {
180180

181181
// yield all IP addresses
182182
for _, g := range generator {
183-
g.each(func(ip net.IP) error {
183+
_ = g.each(func(ip net.IP) error {
184184
ips <- net.IPAddr{IP: ip, Zone: ifname}
185185
time.Sleep(interval)
186186
return nil

internal/conn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (c *Conn) receiver(proto int, conn net.PacketConn) {
9898
// read incoming packets
9999
for {
100100
if n, source, err := conn.ReadFrom(rb); err != nil {
101-
if netErr, ok := err.(net.Error); !ok || !netErr.Temporary() {
101+
if netErr, ok := err.(net.Error); !ok || !netErr.Temporary() { //nolint:staticcheck // needs investigation
102102
break // socket gone
103103
}
104104
} else {
@@ -215,7 +215,7 @@ func (c *Conn) WriteTo(addr *net.IPAddr, seq int, data []byte) error {
215215
if c.Privileged {
216216
_, err = conn.WriteTo(wb, addr)
217217
} else {
218-
conn.WriteTo(wb, &net.UDPAddr{
218+
_, _ = conn.WriteTo(wb, &net.UDPAddr{
219219
IP: addr.IP,
220220
Zone: addr.Zone,
221221
})

internal/payload.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package internal
22

33
import (
4-
"math/rand"
4+
"encoding/binary"
5+
"math/rand/v2"
56
"time"
67

78
"github.com/digineo/go-logwrap"
@@ -13,10 +14,14 @@ var (
1314
// SetLogger allows updating the Logger. For details, see
1415
// "github.com/digineo/go-logwrap".Instance.SetLogger.
1516
SetLogger = Logger.SetLogger
17+
18+
rnd *rand.ChaCha8
1619
)
1720

1821
func init() {
19-
rand.Seed(time.Now().UnixNano())
22+
seed := [32]byte{}
23+
binary.NativeEndian.PutUint64(seed[:], uint64(time.Now().UnixNano()))
24+
rnd = rand.NewChaCha8(seed)
2025
}
2126

2227
// Payload represents additional data appended to outgoing ICMP Echo
@@ -26,9 +31,6 @@ type Payload []byte
2631
// Resize will assign a new payload of the given size to p.
2732
func (p *Payload) Resize(size uint16) {
2833
buf := make([]byte, size)
29-
if _, err := rand.Read(buf); err != nil {
30-
Logger.Errorf("error resizing payload: %v", err)
31-
return
32-
}
34+
_, _ = rnd.Read(buf)
3335
*p = Payload(buf)
3436
}

monitor/history.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ func (h *History) compute() *Metrics {
102102
size := numTotal - numFailure
103103
mean = total / float64(size)
104104
for _, rtt := range data {
105-
sumSquares += math.Pow(rtt-mean, 2)
105+
d := rtt - mean
106+
sumSquares += d * d
106107
}
107108
stddev = time.Duration(math.Sqrt(sumSquares / float64(size)))
108109

request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (req *simpleRequest) close() {
5555
defer func() {
5656
// Double-closing is very unlikely, but a race condition may
5757
// happen when sending fails and a reply is received anyway.
58-
recover()
58+
_ = recover()
5959
}()
6060

6161
close(req.wait)

0 commit comments

Comments
 (0)