Skip to content

Commit

Permalink
lint after Go 1.22
Browse files Browse the repository at this point in the history
Summary: Fix all lint warnings revealed by GitHub CI after go1.22 upgrade

Reviewed By: leoleovich, deathowl

Differential Revision: D54204526
  • Loading branch information
abulimov authored and facebook-github-bot committed Feb 26, 2024
1 parent bc129b0 commit 224a798
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 45 deletions.
2 changes: 1 addition & 1 deletion dnsrocks/cmd/cdbdumpstats/cdbdumpstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func main() {

if *dumbSlotStats {
slotstats := make(map[uint32]int)
err := c.ForEachKeys(func(keyHash uint32, key, value []byte) {
err := c.ForEachKeys(func(keyHash uint32, _, _ []byte) {
slotstats[keyHash]++
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion dnsrocks/db/answer_sorted.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (r *sortedDataReader) IsAuthoritative(q []byte, loc *Location) (ns bool, au

var zoneCutLength int

preIterationCheck := func(q []byte, qLength int) bool {
preIterationCheck := func(_ []byte, qLength int) bool {
zoneCutLength = qLength

return true
Expand Down
2 changes: 1 addition & 1 deletion dnsrocks/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (f *DB) ValidateDbKey(dbKey []byte) error {
err error
keyFound bool
)
parseResult := func(result []byte) error {
parseResult := func(_ []byte) error {
// set to true as soon as first key found
keyFound = true
return nil
Expand Down
2 changes: 1 addition & 1 deletion dnsrocks/db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestDbReload(t *testing.T) {
// DB is closed, and there is no error
mockDbiValid := getBaseMockDBI(ctrl)
// simulates a key hit by returning a value on first call to FindNext, followed by an EOF
foreachCallback := func(key []byte, f func(value []byte) error, context Context) error {
foreachCallback := func(_ []byte, f func(value []byte) error, _ Context) error {
err := f([]byte("{}"))
return err
}
Expand Down
40 changes: 20 additions & 20 deletions dnsrocks/dnsdata/rdb/rdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ func TestRDBAddErrorGettingValue(t *testing.T) {
errorMsg := "I CAN'T GET NO VALUE"
rdb := &RDB{
db: &mockedDB{
get: func(key []byte) ([]byte, error) {
get: func(_ []byte) ([]byte, error) {
return nil, errors.New(errorMsg)
},
put: func(key, value []byte) error {
put: func(_, _ []byte) error {
return nil
},
},
Expand All @@ -116,7 +116,7 @@ func TestRDBAddToNewKey(t *testing.T) {
newValue := []byte{1, 2, 255, 3, 0}
rdb := &RDB{
db: &mockedDB{
get: func(key []byte) ([]byte, error) {
get: func(_ []byte) ([]byte, error) {
return nil, nil
},
put: func(key, value []byte) error {
Expand All @@ -137,7 +137,7 @@ func TestRDBAddErrorAddToExistingKey(t *testing.T) {
newValue := []byte{8, 2, 255, 3, 9, 8, 9}
rdb := &RDB{
db: &mockedDB{
get: func(key []byte) ([]byte, error) {
get: func(_ []byte) ([]byte, error) {
return oldValue, nil
},
put: func(key, value []byte) error {
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestRDBDelErrorGettingKey(t *testing.T) {
errorMsg := "I CAN'T GET NO VALUE"
rdb := &RDB{
db: &mockedDB{
get: func(key []byte) ([]byte, error) {
get: func(_ []byte) ([]byte, error) {
return nil, errors.New(errorMsg)
},
},
Expand All @@ -181,7 +181,7 @@ func TestRDBDelErrorMissingKey(t *testing.T) {
// check that returns error if key does not exist
rdb := &RDB{
db: &mockedDB{
get: func(key []byte) ([]byte, error) {
get: func(_ []byte) ([]byte, error) {
return nil, nil
},
},
Expand All @@ -206,11 +206,11 @@ func TestRDBDelErrorNonExistingValue(t *testing.T) {
require.Equal(t, key, simpleKey)
return simpleValStored, nil
},
put: func(key, value []byte) error {
put: func(_, _ []byte) error {
t.Error("Should not be called")
return nil
},
delete: func(key []byte) error {
delete: func(_ []byte) error {
deleteCalled = true
return nil
},
Expand All @@ -237,11 +237,11 @@ func TestRDBDelErrorTruncatedValue1(t *testing.T) {
require.Equal(t, key, simpleKey)
return simpleValStored, nil
},
put: func(key, value []byte) error {
put: func(_, _ []byte) error {
t.Error("Should not be called")
return nil
},
delete: func(key []byte) error {
delete: func(_ []byte) error {
deleteCalled = true
return nil
},
Expand All @@ -268,11 +268,11 @@ func TestRDBDelErrorTruncatedValue2(t *testing.T) {
require.Equal(t, key, simpleKey)
return simpleValStored, nil
},
put: func(key, value []byte) error {
put: func(_, _ []byte) error {
t.Error("Should not be called")
return nil
},
delete: func(key []byte) error {
delete: func(_ []byte) error {
deleteCalled = true
return nil
},
Expand All @@ -298,7 +298,7 @@ func TestRDBDelOnlyValue(t *testing.T) {
require.Equal(t, key, simpleKey)
return simpleValStored, nil
},
put: func(key, value []byte) error {
put: func(_, _ []byte) error {
t.Error("Should not be called")
return nil
},
Expand Down Expand Up @@ -367,7 +367,7 @@ func TestRDBDelWithOffset(t *testing.T) {
require.Equal(t, test.after, value)
return nil
},
delete: func(key []byte) error {
delete: func(_ []byte) error {
t.Error("Should not be called")
return nil
},
Expand Down Expand Up @@ -561,11 +561,11 @@ func TestRDBContext(t *testing.T) {
require.Equal(t, simpleKey, key)
return test.data, nil
},
put: func(key, value []byte) error {
put: func(_, _ []byte) error {
t.Error("Should not be called")
return nil
},
delete: func(key []byte) error {
delete: func(_ []byte) error {
t.Error("Should not be called")
return nil
},
Expand Down Expand Up @@ -817,19 +817,19 @@ func TestRDBFindFirst(t *testing.T) {
t.Run(fmt.Sprintf("%d", nt), func(t *testing.T) {
rdb := &RDB{
db: &mockedDB{
getMulti: func(readOptions *rocksdb.ReadOptions, keys [][]byte) ([][]byte, []error) {
getMulti: func(_ *rocksdb.ReadOptions, keys [][]byte) ([][]byte, []error) {
require.Equal(t, keys, test.requestedKeys)
return test.getMultiValues, test.getMultiErrors
},
get: func(key []byte) ([]byte, error) {
get: func(_ []byte) ([]byte, error) {
t.Error("Should not be called")
return nil, nil
},
put: func(key, value []byte) error {
put: func(_, _ []byte) error {
t.Error("Should not be called")
return nil
},
delete: func(key []byte) error {
delete: func(_ []byte) error {
t.Error("Should not be called")
return nil
},
Expand Down
8 changes: 4 additions & 4 deletions dnsrocks/nsid/nsid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestNSID(t *testing.T) {
return &src
}
var responseTime time.Time
h.Next = test.HandlerFunc(func(c context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
h.Next = test.HandlerFunc(func(_ context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
responseTime = time.Now()
m := new(dns.Msg)
m.SetReply(r)
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestNoNSIDRequested(t *testing.T) {
rec := dnstest.NewRecorder(w)
h, err := NewHandler(false)
require.NoError(t, err)
h.Next = test.HandlerFunc(func(c context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
h.Next = test.HandlerFunc(func(_ context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
m := new(dns.Msg)
m.SetReply(r)
m.Authoritative = true
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestNoEDNSInQuery(t *testing.T) {
rec := dnstest.NewRecorder(w)
h, err := NewHandler(false)
require.NoError(t, err)
h.Next = test.HandlerFunc(func(c context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
h.Next = test.HandlerFunc(func(_ context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
m := new(dns.Msg)
m.SetReply(r)
m.Authoritative = true
Expand Down Expand Up @@ -147,7 +147,7 @@ func TestEDNSIsDisabled(t *testing.T) {
rec := dnstest.NewRecorder(w)
h, err := NewHandler(false)
require.NoError(t, err)
h.Next = test.HandlerFunc(func(c context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
h.Next = test.HandlerFunc(func(_ context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
m := new(dns.Msg)
m.SetReply(r)
m.Authoritative = true
Expand Down
2 changes: 1 addition & 1 deletion dnswatch/cmd/detailed.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Usage example:
dnswatch detailed
`,

Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
ConfigureVerbosity()

cfg.Detailed = true
Expand Down
2 changes: 1 addition & 1 deletion dnswatch/cmd/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Usage example:
dnswatch exporter --period 3s
`,

Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
ConfigureVerbosity()

cfg.Exporter = true
Expand Down
2 changes: 1 addition & 1 deletion dnswatch/cmd/nettop.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Usage example:
dnswatch nettop --period 3s
`,

Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
ConfigureVerbosity()

cfg.NetTop = true
Expand Down
2 changes: 1 addition & 1 deletion dnswatch/cmd/snoop.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var snoopCmd = &cobra.Command{
Usage example:
dnswatch snoop --list PID,PNAME,QNAME,RIP
`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
ConfigureVerbosity()

if err := snoop.Run(&cfg); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion dnswatch/cmd/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Usage example:
dnswatch sql --csv /tmp/dnswatch_out --period 30s --orderby -LATENCY --groupby PNAME,QNAME
`,

Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
ConfigureVerbosity()

if cfg.Csv == "" {
Expand Down
2 changes: 1 addition & 1 deletion dnswatch/cmd/top.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Usage example:
dnswatch top --period 3s
`,

Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
ConfigureVerbosity()

cfg.Toplike = true
Expand Down
3 changes: 0 additions & 3 deletions dnswatch/snoop/nettop.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package snoop
import (
"fmt"
"math"
"math/rand"
"sort"
"time"

Expand Down Expand Up @@ -259,8 +258,6 @@ func (t *NetTopState) refreshScreen() {

// StartNetTop is the nettop stdout handler
func StartNetTop(refreshChan <-chan map[UniqueDNS]*DisplayInfo, stopChan chan<- bool, refTime time.Duration) {
rand.Seed(time.Now().UnixNano())

err := termbox.Init()
if err != nil {
log.Error("failed to set up screen")
Expand Down
2 changes: 1 addition & 1 deletion dnswatch/snoop/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func determineHostByteOrder() binary.ByteOrder {
func (p *Probe) loadAndAttachProbes() (*libbpfgo.Module, error) {
libbpfgo.SetLoggerCbs(libbpfgo.Callbacks{
LogFilters: []func(libLevel int, msg string) bool{
func(libLevel int, msg string) bool {
func(_ int, _ string) bool {
return !p.Debug
},
},
Expand Down
3 changes: 0 additions & 3 deletions dnswatch/snoop/toplike.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package snoop
import (
"fmt"
"math"
"math/rand"
"sort"
"strconv"
"time"
Expand Down Expand Up @@ -238,8 +237,6 @@ func (t *ToplikeState) refreshScreen() {

// StartTopLike is the toplike stdout handler
func StartTopLike(refreshChan <-chan *ToplikeData, stopChan chan<- bool, refTime time.Duration) {
rand.Seed(time.Now().UnixNano())

err := termbox.Init()
if err != nil {
log.Error("failed to initialize screen")
Expand Down
4 changes: 0 additions & 4 deletions goose/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package main
import (
"flag"
"fmt"
"math/rand"
"net/http"
"os"
"os/signal"
Expand Down Expand Up @@ -85,9 +84,6 @@ func main() {
flag.BoolVar(&reportJSON, "report-json", false, "Report run results to stdout in json format")
flag.Parse()

// Set the seed
rand.Seed(time.Now().UTC().UnixNano())

switch logLevel {
case "debug":
log.SetLevel(log.DebugLevel)
Expand Down

0 comments on commit 224a798

Please sign in to comment.