Skip to content

Commit 2682262

Browse files
authored
fix: use proper go version in module file (#12)
1 parent b0226d1 commit 2682262

File tree

12 files changed

+249
-166
lines changed

12 files changed

+249
-166
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ jobs:
3232
go-version: "1.25.0"
3333

3434
- name: lint
35-
uses: golangci/golangci-lint-action@v6
35+
uses: golangci/golangci-lint-action@v8
3636
with:
37-
version: latest
37+
version: v2.5.0
3838

3939
nix-build:
4040
strategy:

cmd/cli_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77
"testing"
88

9+
"github.com/karol-broda/snitch/internal/errutil"
910
"github.com/karol-broda/snitch/internal/testutil"
1011
)
1112

@@ -407,16 +408,16 @@ func TestEnvironmentVariables(t *testing.T) {
407408
oldEnvVars := make(map[string]string)
408409
for key, value := range tt.envVars {
409410
oldEnvVars[key] = os.Getenv(key)
410-
os.Setenv(key, value)
411+
errutil.Setenv(key, value)
411412
}
412413

413414
// Clean up environment variables
414415
defer func() {
415416
for key, oldValue := range oldEnvVars {
416417
if oldValue == "" {
417-
os.Unsetenv(key)
418+
errutil.Unsetenv(key)
418419
} else {
419-
os.Setenv(key, oldValue)
420+
errutil.Setenv(key, oldValue)
420421
}
421422
}
422423
}()

cmd/ls.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ import (
88
"log"
99
"os"
1010
"os/exec"
11-
"github.com/karol-broda/snitch/internal/collector"
12-
"github.com/karol-broda/snitch/internal/color"
13-
"github.com/karol-broda/snitch/internal/config"
14-
"github.com/karol-broda/snitch/internal/resolver"
1511
"strconv"
1612
"strings"
1713
"text/tabwriter"
1814

1915
"github.com/charmbracelet/lipgloss"
2016
"github.com/spf13/cobra"
17+
18+
"github.com/karol-broda/snitch/internal/collector"
19+
"github.com/karol-broda/snitch/internal/color"
20+
"github.com/karol-broda/snitch/internal/config"
21+
"github.com/karol-broda/snitch/internal/errutil"
22+
"github.com/karol-broda/snitch/internal/resolver"
2123
"github.com/tidwall/pretty"
2224
"golang.org/x/term"
2325
)
@@ -185,7 +187,7 @@ func printCSV(conns []collector.Connection, headers bool, timestamp bool, select
185187

186188
func printPlainTable(conns []collector.Connection, headers bool, timestamp bool, selectedFields []string) {
187189
w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
188-
defer w.Flush()
190+
defer errutil.Flush(w)
189191

190192
if len(selectedFields) == 0 {
191193
selectedFields = []string{"pid", "process", "user", "proto", "state", "laddr", "lport", "raddr", "rport"}
@@ -199,7 +201,7 @@ func printPlainTable(conns []collector.Connection, headers bool, timestamp bool,
199201
for _, field := range selectedFields {
200202
headerRow = append(headerRow, strings.ToUpper(field))
201203
}
202-
fmt.Fprintln(w, strings.Join(headerRow, "\t"))
204+
errutil.Ignore(fmt.Fprintln(w, strings.Join(headerRow, "\t")))
203205
}
204206

205207
for _, conn := range conns {
@@ -208,7 +210,7 @@ func printPlainTable(conns []collector.Connection, headers bool, timestamp bool,
208210
for _, field := range selectedFields {
209211
row = append(row, fieldMap[field])
210212
}
211-
fmt.Fprintln(w, strings.Join(row, "\t"))
213+
errutil.Ignore(fmt.Fprintln(w, strings.Join(row, "\t")))
212214
}
213215
}
214216

cmd/stats.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"log"
99
"os"
1010
"os/signal"
11-
"github.com/karol-broda/snitch/internal/collector"
1211
"sort"
1312
"strconv"
1413
"strings"
@@ -17,6 +16,9 @@ import (
1716
"time"
1817

1918
"github.com/spf13/cobra"
19+
20+
"github.com/karol-broda/snitch/internal/collector"
21+
"github.com/karol-broda/snitch/internal/errutil"
2022
)
2123

2224
type StatsData struct {
@@ -227,61 +229,61 @@ func printStatsCSV(stats *StatsData, headers bool) {
227229

228230
func printStatsTable(stats *StatsData, headers bool) {
229231
w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
230-
defer w.Flush()
232+
defer errutil.Flush(w)
231233

232234
if headers {
233-
fmt.Fprintf(w, "TIMESTAMP\t%s\n", stats.Timestamp.Format(time.RFC3339))
234-
fmt.Fprintf(w, "TOTAL CONNECTIONS\t%d\n", stats.Total)
235-
fmt.Fprintln(w)
235+
errutil.Ignore(fmt.Fprintf(w, "TIMESTAMP\t%s\n", stats.Timestamp.Format(time.RFC3339)))
236+
errutil.Ignore(fmt.Fprintf(w, "TOTAL CONNECTIONS\t%d\n", stats.Total))
237+
errutil.Ignore(fmt.Fprintln(w))
236238
}
237239

238240
// Protocol breakdown
239241
if len(stats.ByProto) > 0 {
240242
if headers {
241-
fmt.Fprintln(w, "BY PROTOCOL:")
242-
fmt.Fprintln(w, "PROTO\tCOUNT")
243+
errutil.Ignore(fmt.Fprintln(w, "BY PROTOCOL:"))
244+
errutil.Ignore(fmt.Fprintln(w, "PROTO\tCOUNT"))
243245
}
244246
protocols := make([]string, 0, len(stats.ByProto))
245247
for proto := range stats.ByProto {
246248
protocols = append(protocols, proto)
247249
}
248250
sort.Strings(protocols)
249251
for _, proto := range protocols {
250-
fmt.Fprintf(w, "%s\t%d\n", strings.ToUpper(proto), stats.ByProto[proto])
252+
errutil.Ignore(fmt.Fprintf(w, "%s\t%d\n", strings.ToUpper(proto), stats.ByProto[proto]))
251253
}
252-
fmt.Fprintln(w)
254+
errutil.Ignore(fmt.Fprintln(w))
253255
}
254256

255257
// State breakdown
256258
if len(stats.ByState) > 0 {
257259
if headers {
258-
fmt.Fprintln(w, "BY STATE:")
259-
fmt.Fprintln(w, "STATE\tCOUNT")
260+
errutil.Ignore(fmt.Fprintln(w, "BY STATE:"))
261+
errutil.Ignore(fmt.Fprintln(w, "STATE\tCOUNT"))
260262
}
261263
states := make([]string, 0, len(stats.ByState))
262264
for state := range stats.ByState {
263265
states = append(states, state)
264266
}
265267
sort.Strings(states)
266268
for _, state := range states {
267-
fmt.Fprintf(w, "%s\t%d\n", state, stats.ByState[state])
269+
errutil.Ignore(fmt.Fprintf(w, "%s\t%d\n", state, stats.ByState[state]))
268270
}
269-
fmt.Fprintln(w)
271+
errutil.Ignore(fmt.Fprintln(w))
270272
}
271273

272274
// Process breakdown (top 10)
273275
if len(stats.ByProc) > 0 {
274276
if headers {
275-
fmt.Fprintln(w, "BY PROCESS (TOP 10):")
276-
fmt.Fprintln(w, "PID\tPROCESS\tCOUNT")
277+
errutil.Ignore(fmt.Fprintln(w, "BY PROCESS (TOP 10):"))
278+
errutil.Ignore(fmt.Fprintln(w, "PID\tPROCESS\tCOUNT"))
277279
}
278280
limit := 10
279281
if len(stats.ByProc) < limit {
280282
limit = len(stats.ByProc)
281283
}
282284
for i := 0; i < limit; i++ {
283285
proc := stats.ByProc[i]
284-
fmt.Fprintf(w, "%d\t%s\t%d\n", proc.PID, proc.Process, proc.Count)
286+
errutil.Ignore(fmt.Fprintf(w, "%d\t%s\t%d\n", proc.PID, proc.Process, proc.Count))
285287
}
286288
}
287289
}

0 commit comments

Comments
 (0)