From b22e778902ffb8b3d28c33ee196d130ebd195f11 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Sun, 21 Jun 2015 13:17:10 +0200 Subject: [PATCH] Error log simplification ported from syndtr-goleveldb branch. --- cmd/mtredisalize/connection.go | 52 ++++++++++++---------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/cmd/mtredisalize/connection.go b/cmd/mtredisalize/connection.go index 28021a8..5d53521 100644 --- a/cmd/mtredisalize/connection.go +++ b/cmd/mtredisalize/connection.go @@ -51,8 +51,11 @@ func (c *Connection) Run() { } func logError(err error) bool { - log.Printf("ERROR: %s\n", err) - return false + if err != nil { + log.Printf("ERROR: %s\n", err) + return false + } + return true } func (c *Connection) Hget(hash, key []byte) bool { @@ -135,10 +138,8 @@ func (c *Connection) Hkeys(hash []byte) bool { } func (c *Connection) Ping() bool { - if _, err := c.conn.Write(redisPong); err != nil { - return logError(err) - } - return true + _, err := c.conn.Write(redisPong) + return logError(err) } func (c *Connection) HSpatial(hash, first, second []byte) bool { @@ -162,25 +163,18 @@ func (c *Connection) HSpatial(hash, first, second []byte) bool { } } - if err = c.writeBulkString(nil); err != nil { - return logError(err) - } - return true + return logError(c.writeBulkString(nil)) } func (c *Connection) writeError(err error) bool { logError(err) - if _, err = c.conn.Write(redisError); err != nil { - return logError(err) - } - return true + _, err = c.conn.Write(redisError) + return logError(err) } func (c *Connection) writeEmptyArray() bool { - if _, err := c.conn.Write(redisEmptyArray); err != nil { - return logError(err) - } - return true + _, err := c.conn.Write(redisEmptyArray) + return logError(err) } func (c *Connection) writeBool(b bool) bool { @@ -190,10 +184,7 @@ func (c *Connection) writeBool(b bool) bool { } else { _, err = c.conn.Write(redisFalse) } - if err != nil { - return logError(err) - } - return true + return logError(err) } func redisLength(prefix byte, s int) []byte { @@ -214,24 +205,17 @@ func (c *Connection) writeBoolArray(arr []bool) bool { } func (c *Connection) writeOk() bool { - if _, err := c.conn.Write(redisOk); err != nil { - return logError(err) - } - return true + _, err := c.conn.Write(redisOk) + return logError(err) } func (c *Connection) writeQueued() bool { - if _, err := c.conn.Write(redisQueued); err != nil { - return logError(err) - } - return true + _, err := c.conn.Write(redisQueued) + return logError(err) } func (c *Connection) writeBlock(data []byte) bool { - if err := c.writeBulkString(data); err != nil { - return logError(err) - } - return true + return logError(c.writeBulkString(data)) } func (c *Connection) writeBulkString(data []byte) (err error) {