Error log simplification ported from syndtr-goleveldb branch.

This commit is contained in:
Sascha L. Teichmann 2015-06-21 13:17:10 +02:00
parent b74671ae63
commit b22e778902

View File

@ -51,8 +51,11 @@ func (c *Connection) Run() {
} }
func logError(err error) bool { func logError(err error) bool {
log.Printf("ERROR: %s\n", err) if err != nil {
return false log.Printf("ERROR: %s\n", err)
return false
}
return true
} }
func (c *Connection) Hget(hash, key []byte) bool { func (c *Connection) Hget(hash, key []byte) bool {
@ -135,10 +138,8 @@ func (c *Connection) Hkeys(hash []byte) bool {
} }
func (c *Connection) Ping() bool { func (c *Connection) Ping() bool {
if _, err := c.conn.Write(redisPong); err != nil { _, err := c.conn.Write(redisPong)
return logError(err) return logError(err)
}
return true
} }
func (c *Connection) HSpatial(hash, first, second []byte) bool { 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(c.writeBulkString(nil))
return logError(err)
}
return true
} }
func (c *Connection) writeError(err error) bool { func (c *Connection) writeError(err error) bool {
logError(err) logError(err)
if _, err = c.conn.Write(redisError); err != nil { _, err = c.conn.Write(redisError)
return logError(err) return logError(err)
}
return true
} }
func (c *Connection) writeEmptyArray() bool { func (c *Connection) writeEmptyArray() bool {
if _, err := c.conn.Write(redisEmptyArray); err != nil { _, err := c.conn.Write(redisEmptyArray)
return logError(err) return logError(err)
}
return true
} }
func (c *Connection) writeBool(b bool) bool { func (c *Connection) writeBool(b bool) bool {
@ -190,10 +184,7 @@ func (c *Connection) writeBool(b bool) bool {
} else { } else {
_, err = c.conn.Write(redisFalse) _, err = c.conn.Write(redisFalse)
} }
if err != nil { return logError(err)
return logError(err)
}
return true
} }
func redisLength(prefix byte, s int) []byte { func redisLength(prefix byte, s int) []byte {
@ -214,24 +205,17 @@ func (c *Connection) writeBoolArray(arr []bool) bool {
} }
func (c *Connection) writeOk() bool { func (c *Connection) writeOk() bool {
if _, err := c.conn.Write(redisOk); err != nil { _, err := c.conn.Write(redisOk)
return logError(err) return logError(err)
}
return true
} }
func (c *Connection) writeQueued() bool { func (c *Connection) writeQueued() bool {
if _, err := c.conn.Write(redisQueued); err != nil { _, err := c.conn.Write(redisQueued)
return logError(err) return logError(err)
}
return true
} }
func (c *Connection) writeBlock(data []byte) bool { func (c *Connection) writeBlock(data []byte) bool {
if err := c.writeBulkString(data); err != nil { return logError(c.writeBulkString(data))
return logError(err)
}
return true
} }
func (c *Connection) writeBulkString(data []byte) (err error) { func (c *Connection) writeBulkString(data []byte) (err error) {