Skip to content

Commit

Permalink
Fix issues reported by golangsci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Adam authored and Daniel Adam committed Feb 15, 2024
1 parent c5bc6c8 commit fa8846c
Show file tree
Hide file tree
Showing 34 changed files with 73 additions and 85 deletions.
2 changes: 1 addition & 1 deletion dtls/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func Client(conn *dtls.Conn, opts ...udp.Option) *udpClient.Conn {
errorsFunc(fmt.Errorf("dtls: %v: %w", conn.RemoteAddr(), err))
}

createBlockWise := func(cc *udpClient.Conn) *blockwise.BlockWise[*udpClient.Conn] {
createBlockWise := func(*udpClient.Conn) *blockwise.BlockWise[*udpClient.Conn] {
return nil
}
if cfg.BlockwiseEnable {
Expand Down
2 changes: 1 addition & 1 deletion dtls/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func TestConnGetSeparateMessage(t *testing.T) {
require.NoError(t, errS)
}()

cc, err := dtls.Dial(l.Addr().String(), dtlsCfg, options.WithHandlerFunc(func(w *responsewriter.ResponseWriter[*client.Conn], r *pool.Message) {
cc, err := dtls.Dial(l.Addr().String(), dtlsCfg, options.WithHandlerFunc(func(_ *responsewriter.ResponseWriter[*client.Conn], r *pool.Message) {
assert.NoError(t, fmt.Errorf("none msg expected comes: %+v", r))
}))
require.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions dtls/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type HandlerFunc = func(*responsewriter.ResponseWriter[*udpClient.Conn], *pool.M
type ErrorFunc = func(error)

// OnNewConnFunc is the callback for new connections.
type OnNewConnFunc = func(cc *udpClient.Conn)
type OnNewConnFunc = func(*udpClient.Conn)

type GetMIDFunc = func() int32

Expand All @@ -34,10 +34,10 @@ var DefaultConfig = func() Config {
}
return inactivity.New(timeout, onInactive)
},
RequestMonitor: func(cc *udpClient.Conn, req *pool.Message) (bool, error) {
RequestMonitor: func(*udpClient.Conn, *pool.Message) (bool, error) {
return false, nil
},
OnNewConn: func(cc *udpClient.Conn) {
OnNewConn: func(*udpClient.Conn) {
// do nothing by default
},
TransmissionNStart: 1,
Expand All @@ -46,7 +46,7 @@ var DefaultConfig = func() Config {
GetMID: message.GetMID,
MTU: udpClient.DefaultMTU,
}
opts.Handler = func(w *responsewriter.ResponseWriter[*udpClient.Conn], r *pool.Message) {
opts.Handler = func(w *responsewriter.ResponseWriter[*udpClient.Conn], _ *pool.Message) {
if err := w.SetResponse(codes.NotFound, message.TextPlain, nil); err != nil {
opts.Errors(fmt.Errorf("dtls server: cannot set response: %w", err))
}
Expand Down
2 changes: 1 addition & 1 deletion dtls/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (s *Server) Stop() {
}

func (s *Server) createConn(connection *coapNet.Conn, inactivityMonitor udpClient.InactivityMonitor, requestMonitor udpClient.RequestMonitorFunc) *udpClient.Conn {
createBlockWise := func(cc *udpClient.Conn) *blockwise.BlockWise[*udpClient.Conn] {
createBlockWise := func(*udpClient.Conn) *blockwise.BlockWise[*udpClient.Conn] {
return nil
}
if s.cfg.BlockwiseEnable {
Expand Down
2 changes: 1 addition & 1 deletion message/codes/codes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func FuzzUnmarshalJSON(f *testing.F) {
f.Add([]byte("0x2a"))
f.Add([]byte("42"))

f.Fuzz(func(t *testing.T, input_data []byte) {
f.Fuzz(func(_ *testing.T, input_data []byte) {
var got Code
_ = got.UnmarshalJSON(input_data)
})
Expand Down
2 changes: 1 addition & 1 deletion message/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func TestQueryOption(t *testing.T) {
}

func FuzzUnmarshalData(f *testing.F) {
f.Fuzz(func(t *testing.T, input_data []byte) {
f.Fuzz(func(_ *testing.T, input_data []byte) {
uoptions := make(Options, 0, 10)
_, _ = uoptions.Unmarshal(input_data, CoapOptionDefs)
})
Expand Down
2 changes: 1 addition & 1 deletion mux/example_logging_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func loggingMiddleware(next mux.Handler) mux.Handler {

func Example_authenticationMiddleware() {
r := mux.NewRouter()
r.HandleFunc("/", func(w mux.ResponseWriter, r *mux.Message) {
r.HandleFunc("/", func(mux.ResponseWriter, *mux.Message) {
// Do something here
})
r.Use(loggingMiddleware)
Expand Down
2 changes: 1 addition & 1 deletion mux/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func NewRouter() *Router {
m: new(sync.RWMutex),
z: make(map[string]Route),
}
router.defaultHandler = HandlerFunc(func(w ResponseWriter, m *Message) {
router.defaultHandler = HandlerFunc(func(w ResponseWriter, _ *Message) {
if err := w.SetResponse(codes.NotFound, message.TextPlain, nil); err != nil {
router.errors(fmt.Errorf("router handler: cannot set response: %w", err))
}
Expand Down
2 changes: 1 addition & 1 deletion mux/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestMux(t *testing.T) {

for _, test := range tests {
t.Run(test.title, func(t *testing.T) {
r.HandleFunc(test.pathTemplate, func(w mux.ResponseWriter, r *mux.Message) {})
r.HandleFunc(test.pathTemplate, func(mux.ResponseWriter, *mux.Message) {})
testRegexp(t, r, test)
testRoute(t, r, test)
err := r.HandleRemove(test.pathTemplate)
Expand Down
2 changes: 1 addition & 1 deletion net/blockwise/blockwise.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func New[C Client](
getSentRequestFromOutside func(token message.Token) (*pool.Message, bool),
) *BlockWise[C] {
if getSentRequestFromOutside == nil {
getSentRequestFromOutside = func(token message.Token) (*pool.Message, bool) { return nil, false }
getSentRequestFromOutside = func(message.Token) (*pool.Message, bool) { return nil, false }
}
return &BlockWise[C]{
cc: cc,
Expand Down
10 changes: 5 additions & 5 deletions net/blockwise/blockwise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func makeDo[C Client](t *testing.T, sender, receiver *BlockWise[C], senderMaxSZX
receiver.Handle(receiverResp, roReq, senderMaxSZX, senderMaxMessageSize, next)
t.Logf("receiver.Handle - receiverResp %v senderResp.Message: %v\n", receiverResp.Message(), roReq)
senderResp := responsewriter.New(sender.cc.AcquireMessage(roReq.Context()), sender.cc)
sender.Handle(senderResp, receiverResp.Message(), receiverMaxSZX, receiverMaxMessageSize, func(w *responsewriter.ResponseWriter[C], r *pool.Message) {
sender.Handle(senderResp, receiverResp.Message(), receiverMaxSZX, receiverMaxMessageSize, func(_ *responsewriter.ResponseWriter[C], r *pool.Message) {
resp = r
})
t.Logf("sender.Handle - senderResp %v receiverResp.Message: %v\n", senderResp.Message(), receiverResp.Message())
Expand Down Expand Up @@ -503,7 +503,7 @@ func makeWriteReq[C Client](sender, receiver *BlockWise[C], senderMaxSZX SZX, se
})
senderResp := responsewriter.New(sender.cc.AcquireMessage(roReq.Context()), sender.cc)
orig := senderResp.Message()
sender.Handle(senderResp, receiverResp.Message(), receiverMaxSZX, receiverMaxMessageSize, func(w *responsewriter.ResponseWriter[C], r *pool.Message) {
sender.Handle(senderResp, receiverResp.Message(), receiverMaxSZX, receiverMaxMessageSize, func(*responsewriter.ResponseWriter[C], *pool.Message) {
})
if orig == senderResp.Message() {
select {
Expand Down Expand Up @@ -552,7 +552,7 @@ func TestBlockWiseWriteTestMessage(t *testing.T) {
},
szx: SZX16,
maxMessageSize: SZX16.Size(),
writetestmessage: makeWriteReq(sender, receiver, SZX16, uint32(SZX16.Size()), SZX16, uint32(SZX16.Size()), func(w *responsewriter.ResponseWriter[*testClient], r *pool.Message) {
writetestmessage: makeWriteReq(sender, receiver, SZX16, uint32(SZX16.Size()), SZX16, uint32(SZX16.Size()), func(_ *responsewriter.ResponseWriter[*testClient], r *pool.Message) {
require.NoError(t, fmt.Errorf("not expected received message: %+v", r))
}),
},
Expand All @@ -569,7 +569,7 @@ func TestBlockWiseWriteTestMessage(t *testing.T) {
},
szx: SZX16,
maxMessageSize: SZX16.Size(),
writetestmessage: makeWriteReq(sender, receiver, SZX16, uint32(SZX16.Size()), SZX1024, uint32(SZX1024.Size()), func(w *responsewriter.ResponseWriter[*testClient], r *pool.Message) {
writetestmessage: makeWriteReq(sender, receiver, SZX16, uint32(SZX16.Size()), SZX1024, uint32(SZX1024.Size()), func(_ *responsewriter.ResponseWriter[*testClient], r *pool.Message) {
require.Equal(t, &testmessage{
ctx: context.Background(),
token: []byte{2},
Expand All @@ -592,7 +592,7 @@ func TestBlockWiseWriteTestMessage(t *testing.T) {
},
szx: SZXBERT,
maxMessageSize: SZXBERT.Size() * 2,
writetestmessage: makeWriteReq(sender, receiver, SZXBERT, uint32(SZXBERT.Size()*2), SZXBERT, uint32(SZXBERT.Size()*5), func(w *responsewriter.ResponseWriter[*testClient], r *pool.Message) {
writetestmessage: makeWriteReq(sender, receiver, SZXBERT, uint32(SZXBERT.Size()*2), SZXBERT, uint32(SZXBERT.Size()*5), func(_ *responsewriter.ResponseWriter[*testClient], r *pool.Message) {
require.Equal(t, &testmessage{
ctx: context.Background(),
token: []byte{'B', 'E', 'R', 'T'},
Expand Down
22 changes: 5 additions & 17 deletions net/client/limitParallelRequests/limitParallelRequests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ func TestLimitParallelRequestsDo(t *testing.T) {
req []*pool.Message
}
tests := []struct {
name string
args args
expNumReqIds int
name string
args args
}{
{
name: "limit 1 endpointLimit 1",
Expand All @@ -66,7 +65,6 @@ func TestLimitParallelRequestsDo(t *testing.T) {
newReq(ctx, t), newReq(ctx, t), newReq(ctx, t),
},
},
expNumReqIds: 24,
},
{
name: "limit n endpointLimit 1",
Expand All @@ -84,7 +82,6 @@ func TestLimitParallelRequestsDo(t *testing.T) {
newReq(ctx, t), newReq(ctx, t), newReq(ctx, t),
},
},
expNumReqIds: 24,
},
{
name: "limit 1 endpointLimit n",
Expand All @@ -102,7 +99,6 @@ func TestLimitParallelRequestsDo(t *testing.T) {
newReq(ctx, t), newReq(ctx, t), newReq(ctx, t),
},
},
expNumReqIds: 24,
},
{
name: "limit n endpointLimit n",
Expand All @@ -120,7 +116,6 @@ func TestLimitParallelRequestsDo(t *testing.T) {
newReq(ctx, t), newReq(ctx, t), newReq(ctx, t),
},
},
expNumReqIds: 24,
},
{
name: "context canceled",
Expand All @@ -138,7 +133,6 @@ func TestLimitParallelRequestsDo(t *testing.T) {
newReq(ctx, t), newReq(canceledCtx, t), newReq(ctx, t),
},
},
expNumReqIds: 16,
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -173,9 +167,8 @@ func TestLimitParallelRequestsDoObserve(t *testing.T) {
req []*pool.Message
}
tests := []struct {
name string
args args
expNumReqIds int
name string
args args
}{
{
name: "limit 1 endpointLimit 1",
Expand All @@ -193,7 +186,6 @@ func TestLimitParallelRequestsDoObserve(t *testing.T) {
newReq(ctx, t), newReq(ctx, t), newReq(ctx, t),
},
},
expNumReqIds: 24,
},
{
name: "limit n endpointLimit 1",
Expand All @@ -211,7 +203,6 @@ func TestLimitParallelRequestsDoObserve(t *testing.T) {
newReq(ctx, t), newReq(ctx, t), newReq(ctx, t),
},
},
expNumReqIds: 24,
},
{
name: "limit 1 endpointLimit n",
Expand All @@ -229,7 +220,6 @@ func TestLimitParallelRequestsDoObserve(t *testing.T) {
newReq(ctx, t), newReq(ctx, t), newReq(ctx, t),
},
},
expNumReqIds: 24,
},
{
name: "limit n endpointLimit n",
Expand All @@ -247,7 +237,6 @@ func TestLimitParallelRequestsDoObserve(t *testing.T) {
newReq(ctx, t), newReq(ctx, t), newReq(ctx, t),
},
},
expNumReqIds: 24,
},
{
name: "context canceled",
Expand All @@ -265,7 +254,6 @@ func TestLimitParallelRequestsDoObserve(t *testing.T) {
newReq(ctx, t), newReq(canceledCtx, t), newReq(ctx, t),
},
},
expNumReqIds: 16,
},
}
for _, tt := range tests {
Expand All @@ -278,7 +266,7 @@ func TestLimitParallelRequestsDoObserve(t *testing.T) {
req.SetMessageID(int32(idx))
go func(r *pool.Message) {
defer wg.Done()
_, err := c.DoObserve(r, func(req *pool.Message) {
_, err := c.DoObserve(r, func(*pool.Message) {
// do nothing
})
require.Error(t, err)
Expand Down
2 changes: 1 addition & 1 deletion net/connUDP.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func IsIPv6(addr net.IP) bool {
}

var DefaultUDPConnConfig = UDPConnConfig{
Errors: func(err error) {
Errors: func(error) {
// don't log any error from fails for multicast requests
},
}
Expand Down
6 changes: 3 additions & 3 deletions net/tlslistener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ func SetTLSConfig(t *testing.T) *tls.Config {
ClientCAs: caRootPool,
RootCAs: caRootPool,

GetConfigForClient: func(info *tls.ClientHelloInfo) (*tls.Config, error) {
GetConfigForClient: func(*tls.ClientHelloInfo) (*tls.Config, error) {
// https://github.com/golang/go/issues/29895
m := tls.Config{
Certificates: []tls.Certificate{cert},
ClientAuth: tls.RequireAnyClientCert,
}
m.VerifyPeerCertificate = func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error {
m.VerifyPeerCertificate = func([][]byte, [][]*x509.Certificate) error {
return nil
}
return &m, nil
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestTLSListenerCheckForInfinitLoop(t *testing.T) {
tlsConn := tls.Client(conn, &tls.Config{
InsecureSkipVerify: true,
Certificates: []tls.Certificate{cert},
VerifyPeerCertificate: func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error {
VerifyPeerCertificate: func([][]byte, [][]*x509.Certificate) error {
errC := conn.Close()
require.NoError(t, errC)
return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestElementExpiration(t *testing.T) {
cache := NewCache[string, string]()

elementToCache := string("elem")
elem := NewElement(elementToCache, time.Now().Add(1*time.Second), func(d string) {
elem := NewElement(elementToCache, time.Now().Add(1*time.Second), func(string) {
expirationInvoked = true
})
loadedElem, _ := cache.LoadOrStore("abcd", elem)
Expand Down Expand Up @@ -141,7 +141,7 @@ func TestPullOutAllFunction(t *testing.T) {
cache.LoadAndDeleteAll()

foundElements := 0
cache.Range(func(key string, value *Element[string]) bool {
cache.Range(func(string, *Element[string]) bool {
foundElements++
return true
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/connections/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (c *Connections) Store(conn Connection) {

func (c *Connections) length() int {
var l int
c.data.Range(func(k, v interface{}) bool {
c.data.Range(func(_, _ interface{}) bool {
l++
return true
})
Expand All @@ -40,7 +40,7 @@ func (c *Connections) length() int {

func (c *Connections) copyConnections() []Connection {
m := make([]Connection, 0, c.length())
c.data.Range(func(key, value interface{}) bool {
c.data.Range(func(_, value interface{}) bool {
con, ok := value.(Connection)
if !ok {
panic(fmt.Errorf("invalid type %T in connections map", con))
Expand Down
8 changes: 4 additions & 4 deletions pkg/sync/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestLoadOrStore(t *testing.T) {
}

newV := "forty two"
v1, l1 := m.LoadOrStoreWithFunc(42, func(value string) string {
v1, l1 := m.LoadOrStoreWithFunc(42, func(string) string {
require.FailNow(t, "unexpected load call")
return ""
}, func() string {
Expand Down Expand Up @@ -142,15 +142,15 @@ func TestReplace(t *testing.T) {
require.True(t, ok)
require.Equal(t, src[1], oldV)

oldV, ok = m.ReplaceWithFunc(1, func(oldValue string, oldLoaded bool) (string, bool) {
oldV, ok = m.ReplaceWithFunc(1, func(string, bool) (string, bool) {
return "", true
})
require.True(t, ok)
require.Equal(t, newV, oldV)
require.Equal(t, len(src)-1, m.Length())

newV = "forty two"
_, ok = m.ReplaceWithFunc(42, func(oldValue string, oldLoaded bool) (string, bool) {
_, ok = m.ReplaceWithFunc(42, func(string, bool) (string, bool) {
return newV, false
})
require.False(t, ok)
Expand All @@ -175,7 +175,7 @@ func TestDelete(t *testing.T) {
_, ok := m.Load(1)
require.False(t, ok)

m.DeleteWithFunc(1, func(value string) {
m.DeleteWithFunc(1, func(string) {
require.FailNow(t, "unexpected deleted value")
})

Expand Down
2 changes: 1 addition & 1 deletion tcp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func Client(conn net.Conn, opts ...Option) *client.Conn {
errorsFunc(fmt.Errorf("tcp: %w", err))
}

createBlockWise := func(cc *client.Conn) *blockwise.BlockWise[*client.Conn] {
createBlockWise := func(*client.Conn) *blockwise.BlockWise[*client.Conn] {
return nil
}
if cfg.BlockwiseEnable {
Expand Down
Loading

0 comments on commit fa8846c

Please sign in to comment.