Skip to content

Commit

Permalink
refactor: remove unused function parameters and correct redundant con…
Browse files Browse the repository at this point in the history
…ditions (#87)

* chore: Remove unnecessary condition in connection close function

* chore: Remove unused parameter in writeMessage function

* Refactor writeMessage function to remove unused parameter

* ignore gosec in tests

---------

Co-authored-by: Pavel Gabriel <alovak@gmail.com>
  • Loading branch information
sho-hata and alovak authored Oct 4, 2024
1 parent b0e60df commit a3abc20
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (c *Connection) close() error {
}
}

if c.Opts.ConnectionClosedHandlers != nil && len(c.Opts.ConnectionClosedHandlers) > 0 {
if len(c.Opts.ConnectionClosedHandlers) > 0 {
for _, handler := range c.Opts.ConnectionClosedHandlers {
go handler(c)
}
Expand Down Expand Up @@ -454,7 +454,7 @@ func (c *Connection) Send(message *iso8583.Message, options ...Option) (*iso8583
return resp, err
}

func (c *Connection) writeMessage(w io.Writer, message *iso8583.Message) error {
func (c *Connection) writeMessage(message *iso8583.Message) error {
if c.Opts.MessageWriter != nil {
err := c.Opts.MessageWriter.WriteMessage(c.conn, message)
if err != nil {
Expand Down Expand Up @@ -577,7 +577,7 @@ func (c *Connection) writeLoop() {
c.pendingRequestsMu.Unlock()
}

err = c.writeMessage(c.conn, req.message)
err = c.writeMessage(req.message)
if err != nil {
c.handleError(fmt.Errorf("writing message: %w", err))

Expand Down
5 changes: 5 additions & 0 deletions connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
"math"
"net"
"net/http"
"sync"
Expand Down Expand Up @@ -1348,6 +1349,10 @@ func (m *messageIO) WriteMessage(w io.Writer, message *iso8583.Message) error {
}

// create header with message length
if len(rawMessage) > math.MaxUint16 {
return fmt.Errorf("message length is out of uint16 range: %d", len(rawMessage))
}
//nolint:gosec // disable G115 as it's a false positive
h := header{
Length: uint16(len(rawMessage)),
}
Expand Down
1 change: 1 addition & 0 deletions pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func TestPool(t *testing.T) {
// Then pool builds and connects connections to all servers
require.Eventually(t, func() bool {
// we expect connectionsCnt counter to be incremented by both servers
//nolint:gosec // disable G115
return atomic.LoadInt32(&connectionsCnt) == int32(serversToStart)
}, 500*time.Millisecond, 50*time.Millisecond, "%d expected connections established, but got %d", serversToStart, atomic.LoadInt32(&connectionsCnt))

Expand Down

0 comments on commit a3abc20

Please sign in to comment.