Skip to content

Commit b06436a

Browse files
committed
Fixed nil point
1 parent e187465 commit b06436a

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

client/client.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,13 @@ func NewLazyClient(conn net.Conn, Addr net.Addr) *Client {
5656
}
5757

5858
func NewAddrClient(addr net.Addr) (*Client, error) {
59-
conn, err := net.Dial(addr.Network(), addr.String())
60-
61-
if err != nil {
62-
return nil, err
63-
}
59+
conn, _ := net.Dial(addr.Network(), addr.String())
6460

6561
return NewLazyClient(conn, addr), nil
6662
}
6763

6864
func NewTcpClient(address string) (*Client, error) {
69-
conn, err := net.Dial("tcp", address)
70-
71-
if err != nil {
72-
return nil, err
73-
}
65+
conn, _ := net.Dial("tcp", address)
7466

7567
return NewLazyClient(conn, &TCPAddr{Addr: address}), nil
7668
}

client/client_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package client
22

33
import (
44
"errors"
5+
"net"
6+
"testing"
7+
"time"
8+
59
"github.com/hyperf/roc"
610
"github.com/hyperf/roc/formatter"
711
"github.com/stretchr/testify/assert"
812
"github.com/stretchr/testify/mock"
9-
"net"
10-
"testing"
11-
"time"
1213
)
1314

1415
type ConnMock struct {
@@ -106,3 +107,9 @@ func TestSendRequest(t *testing.T) {
106107

107108
assert.True(t, ret >= 1)
108109
}
110+
111+
func TestNewLazyClient(t *testing.T) {
112+
c, _ := NewTcpClient("127.0.0.1:12345")
113+
114+
assert.True(t, c.IdGenerator != nil)
115+
}

0 commit comments

Comments
 (0)