Skip to content

Commit 1f1c423

Browse files
committed
Tidied up code
1 parent d529a24 commit 1f1c423

File tree

5 files changed

+9
-39
lines changed

5 files changed

+9
-39
lines changed

connection_handshake.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,9 @@ func (c *connectionHandshakeV1_0) serverSignature(saltedPass []byte) string {
440440
func (c *connectionHandshakeV1_0) handshakeError(code int, message string) error {
441441
if code >= 10 || code <= 20 {
442442
return RQLAuthError{RQLDriverError{rqlError(message)}}
443-
} else {
444-
return RQLDriverError{rqlError(message)}
445443
}
444+
445+
return RQLDriverError{rqlError(message)}
446446
}
447447

448448
func (c *connectionHandshakeV1_0) hashFunc() func() hash.Hash {

connection_helper.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ import "encoding/binary"
55
// Write 'data' to conn
66
func (c *Connection) writeData(data []byte) error {
77
_, err := c.Conn.Write(data[:])
8-
if err != nil {
9-
return err
10-
}
118

12-
return nil
9+
return err
1310
}
1411

1512
func (c *Connection) read(buf []byte, length int) (total int, err error) {
@@ -20,11 +17,8 @@ func (c *Connection) read(buf []byte, length int) (total int, err error) {
2017
}
2118
total += n
2219
}
23-
if err != nil {
24-
return total, err
25-
}
2620

27-
return total, nil
21+
return total, err
2822
}
2923

3024
func (c *Connection) writeQuery(token int64, q []byte) error {

cursor.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,7 @@ func (c *Cursor) IsNil() bool {
466466
defer c.mu.RUnlock()
467467

468468
if len(c.buffer) > 0 {
469-
bufferedItem := c.buffer[0]
470-
if bufferedItem == nil {
471-
return true
472-
}
473-
474-
return false
469+
return c.buffer[0] == nil
475470
}
476471

477472
if len(c.responses) > 0 {
@@ -545,10 +540,7 @@ func (c *Cursor) extend(response *Response) {
545540
}
546541

547542
func (c *Cursor) extendLocked(response *Response) {
548-
for _, response := range response.Responses {
549-
c.responses = append(c.responses, response)
550-
}
551-
543+
c.responses = append(c.responses, response.Responses...)
552544
c.finished = response.Type != p.Response_SUCCESS_PARTIAL
553545
c.fetching = false
554546
c.isAtom = response.Type == p.Response_SUCCESS_ATOM
@@ -652,9 +644,7 @@ func (c *Cursor) bufferNextResponse() error {
652644

653645
// If response is an ATOM then try and convert to an array
654646
if data, ok := value.([]interface{}); ok && c.isAtom {
655-
for _, v := range data {
656-
c.buffer = append(c.buffer, v)
657-
}
647+
c.buffer = append(c.buffer, data...)
658648
} else if value == nil {
659649
c.buffer = append(c.buffer, nil)
660650
} else {

node.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package gorethink
33
import (
44
"sync"
55

6-
"github.com/hailocab/go-hostpool"
76
p "gopkg.in/dancannon/gorethink.v2/ql2"
87
)
98

@@ -15,7 +14,6 @@ type Node struct {
1514

1615
cluster *Cluster
1716
pool *Pool
18-
hpr hostpool.HostPoolResponse
1917

2018
mu sync.RWMutex
2119
closed bool
@@ -91,12 +89,7 @@ func (n *Node) Query(q Query) (cursor *Cursor, err error) {
9189
return nil, ErrInvalidNode
9290
}
9391

94-
cursor, err = n.pool.Query(q)
95-
if err != nil {
96-
return cursor, err
97-
}
98-
99-
return cursor, err
92+
return n.pool.Query(q)
10093
}
10194

10295
// Exec executes a ReQL query using this nodes connection pool.
@@ -105,12 +98,7 @@ func (n *Node) Exec(q Query) (err error) {
10598
return ErrInvalidNode
10699
}
107100

108-
err = n.pool.Exec(q)
109-
if err != nil {
110-
return err
111-
}
112-
113-
return err
101+
return n.pool.Exec(q)
114102
}
115103

116104
// Server returns the server name and server UUID being used by a connection.

pool.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ const maxBadConnRetries = 3
1313

1414
var (
1515
errPoolClosed = errors.New("gorethink: pool is closed")
16-
errConnClosed = errors.New("gorethink: conn is closed")
17-
errConnBusy = errors.New("gorethink: conn is busy")
1816
)
1917

2018
// A Pool is used to store a pool of connections to a single RethinkDB server

0 commit comments

Comments
 (0)