Skip to content

Commit

Permalink
feat: fix some golangci lint warnings (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeii authored Jul 12, 2024
1 parent 36d7a5b commit eada507
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 26 deletions.
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ linters:
- mnd
- inamedparam
- testifylint
- perfsprint
- contextcheck
- revive
linters-settings:
cyclop:
max-complexity: 10
Expand Down
4 changes: 2 additions & 2 deletions cmd/swat4master/modules/browser/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewBrowser(

lc.Append(fx.Hook{
OnStart: func(context.Context) error {
go func() {
go func() { // nolint: contextcheck
logger.Info().
Str("listen", cfg.BrowserListenAddr).Dur("timeout", cfg.BrowserClientTimeout).
Msg("Starting browser")
Expand All @@ -53,7 +53,7 @@ func NewBrowser(
<-ready
return nil
},
OnStop: func(stopCtx context.Context) error {
OnStop: func(_ context.Context) error {
logger.Info().Msg("Stopping browser")
if err := svr.Stop(); err != nil {
logger.Error().
Expand Down
2 changes: 1 addition & 1 deletion cmd/swat4master/modules/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewReporter(

lc.Append(fx.Hook{
OnStart: func(context.Context) error {
go func() {
go func() { // nolint: contextcheck
logger.Info().Str("listen", cfg.ReporterListenAddr).Msg("Starting reporter")
if err := svr.Listen(); err != nil {
logger.Error().Err(err).Msg("Reporter UDP server exited prematurely")
Expand Down
2 changes: 1 addition & 1 deletion internal/core/usecases/addserver/addserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (uc UseCase) createServerFromAddress(
return server.Blank, err
}

if svr, err = uc.serverRepo.Add(ctx, svr, func(upd *server.Server) bool {
if svr, err = uc.serverRepo.Add(ctx, svr, func(_ *server.Server) bool {
// a server with exactly same address was created in the process,
// we cannot proceed further
return false
Expand Down
2 changes: 1 addition & 1 deletion internal/core/usecases/removeserver/removeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (uc UseCase) Execute(
return ErrInstanceAddrMismatch
}

if err = uc.serverRepo.Remove(ctx, svr, func(s *server.Server) bool {
if err = uc.serverRepo.Remove(ctx, svr, func(_ *server.Server) bool {
return true
}); err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion internal/persistence/memory/servers/servers_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// nolint:revive
package servers_test

import (
Expand Down Expand Up @@ -301,7 +302,7 @@ func TestServerMemoryRepo_CreateOrUpdate_Created(t *testing.T) {

svr := server.MustNew(net.ParseIP("1.1.1.1"), 10480, 10481)
svr.UpdateDiscoveryStatus(ds.Master)
svr, err := repo.AddOrUpdate(ctx, svr, func(s *server.Server) {
svr, err := repo.AddOrUpdate(ctx, svr, func(_ *server.Server) {
panic("should not be called")
})
require.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion internal/reporter/handlers/heartbeat/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/binary"
"encoding/hex"
"errors"
"fmt"
"net"
"strconv"
Expand Down Expand Up @@ -145,7 +146,7 @@ func parseAddrFromHeartbeatParams(
gamePort, ok1 := parseNumericField(fields, "hostport")
queryPort, ok2 := parseNumericField(fields, "localport")
if !ok1 || !ok2 {
return addr.Blank, -1, fmt.Errorf("missing hostport or localport field")
return addr.Blank, -1, errors.New("missing hostport or localport field")
}
svrAddr, err := addr.New(connAddr.IP, gamePort)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions internal/services/discovery/probing/probing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestProbingService_ProbeDetails_RetryOnError(t *testing.T) {
"positive case for existing server",
ds.Details,
true,
func(ctx context.Context, conn *net.UDPConn, udpAddr *net.UDPAddr, bytes []byte) {
func(_ context.Context, conn *net.UDPConn, udpAddr *net.UDPAddr, _ []byte) {
packet := []byte(
"\\hostname\\-==MYT Team Svr==-\\numplayers\\0\\maxplayers\\16" +
"\\gametype\\VIP Escort\\gamevariant\\SWAT 4\\mapname\\Qwik Fuel Convenience Store" +
Expand All @@ -196,7 +196,7 @@ func TestProbingService_ProbeDetails_RetryOnError(t *testing.T) {
"good response for new server",
ds.NoStatus,
false,
func(ctx context.Context, conn *net.UDPConn, udpAddr *net.UDPAddr, bytes []byte) {
func(_ context.Context, conn *net.UDPConn, udpAddr *net.UDPAddr, _ []byte) {
packet := []byte(
"\\hostname\\-==MYT Team Svr==-\\numplayers\\0\\maxplayers\\16" +
"\\gametype\\VIP Escort\\gamevariant\\SWAT 4\\mapname\\Qwik Fuel Convenience Store" +
Expand Down Expand Up @@ -227,7 +227,7 @@ func TestProbingService_ProbeDetails_RetryOnError(t *testing.T) {
"no valid response for existing server - no queryid",
ds.Master | ds.Details | ds.Info,
true,
func(ctx context.Context, conn *net.UDPConn, udpAddr *net.UDPAddr, bytes []byte) {
func(_ context.Context, conn *net.UDPConn, udpAddr *net.UDPAddr, _ []byte) {
packet := []byte(
"\\hostname\\-==MYT Team Svr==-\\numplayers\\0\\maxplayers\\16\\gametype\\VIP Escort" +
"\\gamevariant\\SWAT 4\\mapname\\Qwik Fuel Convenience Store\\hostport\\10480" +
Expand All @@ -243,7 +243,7 @@ func TestProbingService_ProbeDetails_RetryOnError(t *testing.T) {
"no valid response for existing server - validation",
ds.Details,
true,
func(ctx context.Context, conn *net.UDPConn, udpAddr *net.UDPAddr, bytes []byte) {
func(_ context.Context, conn *net.UDPConn, udpAddr *net.UDPAddr, _ []byte) {
packet := []byte(
"\\hostname\\-==MYT Team Svr==-\\numplayers\\-1\\maxplayers\\16" +
"\\gametype\\VIP Escort\\gamevariant\\SWAT 4\\mapname\\Qwik Fuel Convenience Store" +
Expand All @@ -258,7 +258,7 @@ func TestProbingService_ProbeDetails_RetryOnError(t *testing.T) {
"no valid response for new server",
ds.NoStatus,
false,
func(ctx context.Context, conn *net.UDPConn, udpAddr *net.UDPAddr, bytes []byte) {
func(_ context.Context, conn *net.UDPConn, udpAddr *net.UDPAddr, _ []byte) {
packet := []byte(
"\\hostname\\-==MYT Team Svr==-\\numplayers\\0\\maxplayers\\16\\gametype\\VIP Escort" +
"\\gamevariant\\SWAT 4\\mapname\\Qwik Fuel Convenience Store\\hostport\\10480" +
Expand Down
6 changes: 3 additions & 3 deletions internal/testutils/browsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package testutils

import (
"encoding/binary"
"fmt"
"net"
"strconv"
"strings"

"github.com/sergeii/swat4master/pkg/binutils"
Expand All @@ -20,7 +20,7 @@ func GenBrowserChallenge(l uint) []byte {
}

func WithBrowserChallengeLength(l int) func([]byte) int {
return func(req []byte) int {
return func(_ []byte) int {
return l
}
}
Expand Down Expand Up @@ -93,7 +93,7 @@ func UnpackServerList(resp []byte) []map[string]string {
for unparsed[0] == 0x51 {
server := map[string]string{
"host": net.IPv4(unparsed[1], unparsed[2], unparsed[3], unparsed[4]).String(),
"port": fmt.Sprintf("%d", binary.BigEndian.Uint16(unparsed[5:7])),
"port": strconv.FormatUint(uint64(binary.BigEndian.Uint16(unparsed[5:7])), 10),
}
unparsed = unparsed[7:]
for i := range fields {
Expand Down
6 changes: 3 additions & 3 deletions internal/testutils/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Response struct {
type TestRequestOpt func(*http.Request, *http.Response)

func MustBindJSON(v interface{}) TestRequestOpt {
return func(req *http.Request, resp *http.Response) {
return func(_ *http.Request, resp *http.Response) {
if resp != nil {
body, err := io.ReadAll(resp.Body)
if err != nil {
Expand All @@ -29,7 +29,7 @@ func MustBindJSON(v interface{}) TestRequestOpt {
}

func MustHaveNoBody() TestRequestOpt {
return func(req *http.Request, resp *http.Response) {
return func(_ *http.Request, resp *http.Response) {
if resp != nil {
body, err := io.ReadAll(resp.Body)
if err != nil {
Expand All @@ -56,7 +56,7 @@ func DoTestRequest(

// disable redirects
client := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
CheckRedirect: func(_ *http.Request, _ []*http.Request) error {
return http.ErrUseLastResponse
},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/tcp/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestServerListen(t *testing.T) {

server, err := tcp.New(
"localhost:0", // 0 - listen an any available port
tcp.HandleFunc(func(ctx context.Context, conn *net.TCPConn) {
tcp.HandleFunc(func(_ context.Context, conn *net.TCPConn) {
defer conn.Close()
buf := make([]byte, 1024)
n, _ := conn.Read(buf)
Expand Down Expand Up @@ -58,7 +58,7 @@ func TestServerTimeout(t *testing.T) {

server, err := tcp.New(
"localhost:0", // 0 - listen an any available port
tcp.HandleFunc(func(ctx context.Context, conn *net.TCPConn) {
tcp.HandleFunc(func(_ context.Context, conn *net.TCPConn) {
defer conn.Close()
buf := make([]byte, 1024)
n, _ := conn.Read(buf)
Expand Down
2 changes: 1 addition & 1 deletion pkg/udp/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestServerListen(t *testing.T) {

server, err := udp.New(
"localhost:0", // 0 - listen an any available port
udp.HandleFunc(func(ctx context.Context, conn *net.UDPConn, addr *net.UDPAddr, req []byte) {
udp.HandleFunc(func(_ context.Context, conn *net.UDPConn, addr *net.UDPAddr, req []byte) {
resp := req
slices.Reverse(resp)
conn.WriteToUDP(resp, addr) // nolint: errcheck
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestCollector_Run(t *testing.T) {
}),
collector.Module,
fx.NopLogger,
fx.Invoke(func(_ *collector.Collector, m *monitoring.MetricService) {}),
fx.Invoke(func(_ *collector.Collector, _ *monitoring.MetricService) {}),
fx.Populate(&metrics, &repo),
)
app.Start(context.TODO()) // nolint: errcheck
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/prober_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestProber_Run(t *testing.T) {
responses2 := make(chan []byte)
var i2 int64
udp2, cancel2 := gs1.ServerFactory(
func(ctx context.Context, conn *net.UDPConn, addr *net.UDPAddr, req []byte) {
func(_ context.Context, conn *net.UDPConn, addr *net.UDPAddr, _ []byte) {
packet := <-responses2
conn.WriteToUDP(packet, addr) // nolint: errcheck
atomic.AddInt64(&i2, 1)
Expand Down

0 comments on commit eada507

Please sign in to comment.