Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove unused function parameters and correct redundant conditions #87

Merged
merged 4 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading