Skip to content

Commit

Permalink
Tidied up code
Browse files Browse the repository at this point in the history
  • Loading branch information
dancannon committed May 22, 2016
1 parent d529a24 commit 1f1c423
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 39 deletions.
4 changes: 2 additions & 2 deletions connection_handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,9 @@ func (c *connectionHandshakeV1_0) serverSignature(saltedPass []byte) string {
func (c *connectionHandshakeV1_0) handshakeError(code int, message string) error {
if code >= 10 || code <= 20 {
return RQLAuthError{RQLDriverError{rqlError(message)}}
} else {
return RQLDriverError{rqlError(message)}
}

return RQLDriverError{rqlError(message)}
}

func (c *connectionHandshakeV1_0) hashFunc() func() hash.Hash {
Expand Down
10 changes: 2 additions & 8 deletions connection_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import "encoding/binary"
// Write 'data' to conn
func (c *Connection) writeData(data []byte) error {
_, err := c.Conn.Write(data[:])
if err != nil {
return err
}

return nil
return err
}

func (c *Connection) read(buf []byte, length int) (total int, err error) {
Expand All @@ -20,11 +17,8 @@ func (c *Connection) read(buf []byte, length int) (total int, err error) {
}
total += n
}
if err != nil {
return total, err
}

return total, nil
return total, err
}

func (c *Connection) writeQuery(token int64, q []byte) error {
Expand Down
16 changes: 3 additions & 13 deletions cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,7 @@ func (c *Cursor) IsNil() bool {
defer c.mu.RUnlock()

if len(c.buffer) > 0 {
bufferedItem := c.buffer[0]
if bufferedItem == nil {
return true
}

return false
return c.buffer[0] == nil
}

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

func (c *Cursor) extendLocked(response *Response) {
for _, response := range response.Responses {
c.responses = append(c.responses, response)
}

c.responses = append(c.responses, response.Responses...)
c.finished = response.Type != p.Response_SUCCESS_PARTIAL
c.fetching = false
c.isAtom = response.Type == p.Response_SUCCESS_ATOM
Expand Down Expand Up @@ -652,9 +644,7 @@ func (c *Cursor) bufferNextResponse() error {

// If response is an ATOM then try and convert to an array
if data, ok := value.([]interface{}); ok && c.isAtom {
for _, v := range data {
c.buffer = append(c.buffer, v)
}
c.buffer = append(c.buffer, data...)
} else if value == nil {
c.buffer = append(c.buffer, nil)
} else {
Expand Down
16 changes: 2 additions & 14 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package gorethink
import (
"sync"

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

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

cluster *Cluster
pool *Pool
hpr hostpool.HostPoolResponse

mu sync.RWMutex
closed bool
Expand Down Expand Up @@ -91,12 +89,7 @@ func (n *Node) Query(q Query) (cursor *Cursor, err error) {
return nil, ErrInvalidNode
}

cursor, err = n.pool.Query(q)
if err != nil {
return cursor, err
}

return cursor, err
return n.pool.Query(q)
}

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

err = n.pool.Exec(q)
if err != nil {
return err
}

return err
return n.pool.Exec(q)
}

// Server returns the server name and server UUID being used by a connection.
Expand Down
2 changes: 0 additions & 2 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const maxBadConnRetries = 3

var (
errPoolClosed = errors.New("gorethink: pool is closed")
errConnClosed = errors.New("gorethink: conn is closed")
errConnBusy = errors.New("gorethink: conn is busy")
)

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

0 comments on commit 1f1c423

Please sign in to comment.