Skip to content

Commit b5d7e58

Browse files
committed
all: apply golint fixes
1 parent 14db8f5 commit b5d7e58

15 files changed

+29
-47
lines changed

internal/inproc/conn.go

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ func (c *conn) write(data []byte) (int, error) {
5858
case <-c.wdeadline.wait():
5959
return n, timeoutError{}
6060
}
61-
return n, nil
6261
}
6362

6463
func (c *conn) Read(data []byte) (int, error) {

internal/inproc/inproc.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,14 @@ func Dial(addr string) (net.Conn, error) {
171171
}
172172
mgr.cv.Wait()
173173
}
174-
panic("unreachable")
175174
}
176175

177176
// Addr represents an in-process "network" end-point address.
178177
type Addr string
179178

180179
// String implements net.Addr.String
181180
func (a Addr) String() string {
182-
s := string(a)
183-
if strings.HasPrefix(s, "inproc://") {
184-
s = s[len("inproc://"):]
185-
}
186-
return s
181+
return strings.TrimPrefix(string(a), "inproc://")
187182
}
188183

189184
// Network returns the name of the network.

msgio.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func (mw *mwriter) rmConn(w *Conn) {
167167

168168
func (w *mwriter) write(ctx context.Context, msg Msg) error {
169169
w.sem.lock()
170-
grp, ctx := errgroup.WithContext(ctx)
170+
grp, _ := errgroup.WithContext(ctx)
171171
w.mu.Lock()
172172
for i := range w.ws {
173173
ww := w.ws[i]

protocol.go

-7
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@ func asString(slice []byte) string {
6161
return string(slice[:i])
6262
}
6363

64-
func asByte(b bool) byte {
65-
if b {
66-
return 0x01
67-
}
68-
return 0x00
69-
}
70-
7164
func asBool(b byte) (bool, error) {
7265
switch b {
7366
case 0x00:

router.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func (mw *routerMWriter) rmConn(w *Conn) {
225225

226226
func (w *routerMWriter) write(ctx context.Context, msg Msg) error {
227227
w.sem.lock()
228-
grp, ctx := errgroup.WithContext(ctx)
228+
grp, _ := errgroup.WithContext(ctx)
229229
w.mu.Lock()
230230
id := msg.Frames[0]
231231
dmsg := NewMsgFrom(msg.Frames[1:]...)

security/null/null_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestHandshakeReqRep(t *testing.T) {
6464
rep := zmq4.NewRep(ctx, zmq4.WithSecurity(sec))
6565
defer rep.Close()
6666

67-
grp, ctx := errgroup.WithContext(ctx)
67+
grp, _ := errgroup.WithContext(ctx)
6868
grp.Go(func() error {
6969
err := rep.Listen(ep)
7070
if err != nil {

security/plain/plain.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (sec *security) Handshake(conn *zmq4.Conn, server bool) error {
5050
// FIXME(sbinet): perform a real authentication
5151
err = validateHello(cmd.Body)
5252
if err != nil {
53-
conn.SendCmd(zmq4.CmdError, []byte("invalid")) // FIXME(sbinet) correct ERROR reason
53+
_ = conn.SendCmd(zmq4.CmdError, []byte("invalid")) // FIXME(sbinet) correct ERROR reason
5454
return fmt.Errorf("security/plain: could not authenticate client: %w", err)
5555
}
5656

@@ -71,7 +71,7 @@ func (sec *security) Handshake(conn *zmq4.Conn, server bool) error {
7171

7272
raw, err := conn.Meta.MarshalZMTP()
7373
if err != nil {
74-
conn.SendCmd(zmq4.CmdError, []byte("invalid")) // FIXME(sbinet) correct ERROR reason
74+
_ = conn.SendCmd(zmq4.CmdError, []byte("invalid")) // FIXME(sbinet) correct ERROR reason
7575
return fmt.Errorf("security/plain: could not serialize metadata: %w", err)
7676
}
7777

@@ -97,13 +97,13 @@ func (sec *security) Handshake(conn *zmq4.Conn, server bool) error {
9797
return fmt.Errorf("security/plain: could not receive WELCOME from server: %w", err)
9898
}
9999
if cmd.Name != zmq4.CmdWelcome {
100-
conn.SendCmd(zmq4.CmdError, []byte("invalid command")) // FIXME(sbinet) correct ERROR reason
100+
_ = conn.SendCmd(zmq4.CmdError, []byte("invalid command")) // FIXME(sbinet) correct ERROR reason
101101
return fmt.Errorf("security/plain: expected a WELCOME command from server: %w", err)
102102
}
103103

104104
raw, err := conn.Meta.MarshalZMTP()
105105
if err != nil {
106-
conn.SendCmd(zmq4.CmdError, []byte("internal error")) // FIXME(sbinet) correct ERROR reason
106+
_ = conn.SendCmd(zmq4.CmdError, []byte("internal error")) // FIXME(sbinet) correct ERROR reason
107107
return fmt.Errorf("security/plain: could not serialize metadata: %w", err)
108108
}
109109

@@ -117,7 +117,7 @@ func (sec *security) Handshake(conn *zmq4.Conn, server bool) error {
117117
return fmt.Errorf("security/plain: could not receive READY from server: %w", err)
118118
}
119119
if cmd.Name != zmq4.CmdReady {
120-
conn.SendCmd(zmq4.CmdError, []byte("invalid command")) // FIXME(sbinet) correct ERROR reason
120+
_ = conn.SendCmd(zmq4.CmdError, []byte("invalid command")) // FIXME(sbinet) correct ERROR reason
121121
return fmt.Errorf("security/plain: expected a READY command from server: %w", err)
122122
}
123123

security/plain/plain_cxx_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import (
2020
"golang.org/x/sync/errgroup"
2121
)
2222

23+
var (
24+
repQuit = zmq4.NewMsgString("bye")
25+
)
26+
2327
func TestMain(m *testing.M) {
2428
auth := czmq4.NewAuth()
2529

security/plain/plain_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
var (
2424
reqQuit = zmq4.NewMsgString("QUIT")
25-
repQuit = zmq4.NewMsgString("bye")
2625
)
2726

2827
func TestSecurity(t *testing.T) {
@@ -68,7 +67,7 @@ func TestHandshakeReqRep(t *testing.T) {
6867
rep := zmq4.NewRep(ctx, zmq4.WithSecurity(sec))
6968
defer rep.Close()
7069

71-
grp, ctx := errgroup.WithContext(ctx)
70+
grp, _ := errgroup.WithContext(ctx)
7271
grp.Go(func() error {
7372
err := rep.Listen(ep)
7473
if err != nil {

security_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestNullHandshakeReqRep(t *testing.T) {
6262
rep := NewRep(ctx, WithSecurity(sec), WithLogger(Devnull))
6363
defer rep.Close()
6464

65-
grp, ctx := errgroup.WithContext(ctx)
65+
grp, _ := errgroup.WithContext(ctx)
6666
grp.Go(func() error {
6767
err := rep.Listen(ep)
6868
if err != nil {

transport.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,14 @@ var drivers = transports{
6565
}
6666

6767
func init() {
68-
RegisterTransport("ipc", transport.New("unix"))
69-
RegisterTransport("tcp", transport.New("tcp"))
70-
RegisterTransport("udp", transport.New("udp"))
71-
RegisterTransport("inproc", inproc.Transport{})
68+
must := func(err error) {
69+
if err != nil {
70+
panic(fmt.Errorf("%+v", err))
71+
}
72+
}
73+
74+
must(RegisterTransport("ipc", transport.New("unix")))
75+
must(RegisterTransport("tcp", transport.New("tcp")))
76+
must(RegisterTransport("udp", transport.New("udp")))
77+
must(RegisterTransport("inproc", inproc.Transport{}))
7278
}

zmq4_pubsub_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func TestPubSub(t *testing.T) {
123123
wg1.Add(len(subs))
124124
wg2.Add(len(subs))
125125

126-
grp, ctx := errgroup.WithContext(ctx)
126+
grp, _ := errgroup.WithContext(ctx)
127127
grp.Go(func() error {
128128

129129
err := tc.pub.Listen(ep)
@@ -225,7 +225,7 @@ func TestPubSubClosedSub(t *testing.T) {
225225

226226
const nmsgs = 100 // the number of messages do not matter
227227

228-
grp, ctx := errgroup.WithContext(ctx)
228+
grp, _ := errgroup.WithContext(ctx)
229229
grp.Go(func() error {
230230
err := pub.Listen(ep)
231231
if err != nil {

zmq4_pushpull_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestPushPull(t *testing.T) {
6969
ctx, timeout := context.WithTimeout(context.Background(), 20*time.Second)
7070
defer timeout()
7171

72-
grp, ctx := errgroup.WithContext(ctx)
72+
grp, _ := errgroup.WithContext(ctx)
7373
grp.Go(func() error {
7474

7575
err := tc.push.Listen(ep)

zmq4_routerdealer_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func TestRouterDealer(t *testing.T) {
125125

126126
var seenMu sync.RWMutex
127127
seen := make(map[string]int)
128-
grp, ctx := errgroup.WithContext(ctx)
128+
grp, _ := errgroup.WithContext(ctx)
129129
grp.Go(func() error {
130130

131131
err := router.Listen(ep)

zmq4_test.go

-14
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"log"
1313
"net"
1414
"os"
15-
"strconv"
1615
"strings"
1716
)
1817

@@ -49,19 +48,6 @@ func EndPoint(transport string) (string, error) {
4948
}
5049
}
5150

52-
func getTCPPort() (string, error) {
53-
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
54-
if err != nil {
55-
return "", err
56-
}
57-
l, err := net.ListenTCP("tcp", addr)
58-
if err != nil {
59-
return "", err
60-
}
61-
defer l.Close()
62-
return strconv.Itoa(l.Addr().(*net.TCPAddr).Port), nil
63-
}
64-
6551
func cleanUp(ep string) {
6652
switch {
6753
case strings.HasPrefix(ep, "ipc://"):

0 commit comments

Comments
 (0)