Skip to content

Commit

Permalink
all: apply golint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sbinet committed Oct 21, 2020
1 parent 14db8f5 commit b5d7e58
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 47 deletions.
1 change: 0 additions & 1 deletion internal/inproc/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func (c *conn) write(data []byte) (int, error) {
case <-c.wdeadline.wait():
return n, timeoutError{}
}
return n, nil
}

func (c *conn) Read(data []byte) (int, error) {
Expand Down
7 changes: 1 addition & 6 deletions internal/inproc/inproc.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,14 @@ func Dial(addr string) (net.Conn, error) {
}
mgr.cv.Wait()
}
panic("unreachable")
}

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

// String implements net.Addr.String
func (a Addr) String() string {
s := string(a)
if strings.HasPrefix(s, "inproc://") {
s = s[len("inproc://"):]
}
return s
return strings.TrimPrefix(string(a), "inproc://")
}

// Network returns the name of the network.
Expand Down
2 changes: 1 addition & 1 deletion msgio.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (mw *mwriter) rmConn(w *Conn) {

func (w *mwriter) write(ctx context.Context, msg Msg) error {
w.sem.lock()
grp, ctx := errgroup.WithContext(ctx)
grp, _ := errgroup.WithContext(ctx)
w.mu.Lock()
for i := range w.ws {
ww := w.ws[i]
Expand Down
7 changes: 0 additions & 7 deletions protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ func asString(slice []byte) string {
return string(slice[:i])
}

func asByte(b bool) byte {
if b {
return 0x01
}
return 0x00
}

func asBool(b byte) (bool, error) {
switch b {
case 0x00:
Expand Down
2 changes: 1 addition & 1 deletion router.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (mw *routerMWriter) rmConn(w *Conn) {

func (w *routerMWriter) write(ctx context.Context, msg Msg) error {
w.sem.lock()
grp, ctx := errgroup.WithContext(ctx)
grp, _ := errgroup.WithContext(ctx)
w.mu.Lock()
id := msg.Frames[0]
dmsg := NewMsgFrom(msg.Frames[1:]...)
Expand Down
2 changes: 1 addition & 1 deletion security/null/null_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestHandshakeReqRep(t *testing.T) {
rep := zmq4.NewRep(ctx, zmq4.WithSecurity(sec))
defer rep.Close()

grp, ctx := errgroup.WithContext(ctx)
grp, _ := errgroup.WithContext(ctx)
grp.Go(func() error {
err := rep.Listen(ep)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions security/plain/plain.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (sec *security) Handshake(conn *zmq4.Conn, server bool) error {
// FIXME(sbinet): perform a real authentication
err = validateHello(cmd.Body)
if err != nil {
conn.SendCmd(zmq4.CmdError, []byte("invalid")) // FIXME(sbinet) correct ERROR reason
_ = conn.SendCmd(zmq4.CmdError, []byte("invalid")) // FIXME(sbinet) correct ERROR reason
return fmt.Errorf("security/plain: could not authenticate client: %w", err)
}

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

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

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

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

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

Expand Down
4 changes: 4 additions & 0 deletions security/plain/plain_cxx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import (
"golang.org/x/sync/errgroup"
)

var (
repQuit = zmq4.NewMsgString("bye")
)

func TestMain(m *testing.M) {
auth := czmq4.NewAuth()

Expand Down
3 changes: 1 addition & 2 deletions security/plain/plain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

var (
reqQuit = zmq4.NewMsgString("QUIT")
repQuit = zmq4.NewMsgString("bye")
)

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

grp, ctx := errgroup.WithContext(ctx)
grp, _ := errgroup.WithContext(ctx)
grp.Go(func() error {
err := rep.Listen(ep)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestNullHandshakeReqRep(t *testing.T) {
rep := NewRep(ctx, WithSecurity(sec), WithLogger(Devnull))
defer rep.Close()

grp, ctx := errgroup.WithContext(ctx)
grp, _ := errgroup.WithContext(ctx)
grp.Go(func() error {
err := rep.Listen(ep)
if err != nil {
Expand Down
14 changes: 10 additions & 4 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,14 @@ var drivers = transports{
}

func init() {
RegisterTransport("ipc", transport.New("unix"))
RegisterTransport("tcp", transport.New("tcp"))
RegisterTransport("udp", transport.New("udp"))
RegisterTransport("inproc", inproc.Transport{})
must := func(err error) {
if err != nil {
panic(fmt.Errorf("%+v", err))
}
}

must(RegisterTransport("ipc", transport.New("unix")))
must(RegisterTransport("tcp", transport.New("tcp")))
must(RegisterTransport("udp", transport.New("udp")))
must(RegisterTransport("inproc", inproc.Transport{}))
}
4 changes: 2 additions & 2 deletions zmq4_pubsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestPubSub(t *testing.T) {
wg1.Add(len(subs))
wg2.Add(len(subs))

grp, ctx := errgroup.WithContext(ctx)
grp, _ := errgroup.WithContext(ctx)
grp.Go(func() error {

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

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

grp, ctx := errgroup.WithContext(ctx)
grp, _ := errgroup.WithContext(ctx)
grp.Go(func() error {
err := pub.Listen(ep)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion zmq4_pushpull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestPushPull(t *testing.T) {
ctx, timeout := context.WithTimeout(context.Background(), 20*time.Second)
defer timeout()

grp, ctx := errgroup.WithContext(ctx)
grp, _ := errgroup.WithContext(ctx)
grp.Go(func() error {

err := tc.push.Listen(ep)
Expand Down
2 changes: 1 addition & 1 deletion zmq4_routerdealer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestRouterDealer(t *testing.T) {

var seenMu sync.RWMutex
seen := make(map[string]int)
grp, ctx := errgroup.WithContext(ctx)
grp, _ := errgroup.WithContext(ctx)
grp.Go(func() error {

err := router.Listen(ep)
Expand Down
14 changes: 0 additions & 14 deletions zmq4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"log"
"net"
"os"
"strconv"
"strings"
)

Expand Down Expand Up @@ -49,19 +48,6 @@ func EndPoint(transport string) (string, error) {
}
}

func getTCPPort() (string, error) {
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
if err != nil {
return "", err
}
l, err := net.ListenTCP("tcp", addr)
if err != nil {
return "", err
}
defer l.Close()
return strconv.Itoa(l.Addr().(*net.TCPAddr).Port), nil
}

func cleanUp(ep string) {
switch {
case strings.HasPrefix(ep, "ipc://"):
Expand Down

0 comments on commit b5d7e58

Please sign in to comment.