2
0

Fix some golint errors

- Add comments
- Rename variables
- Remove unnecessary "else"
This commit is contained in:
Jack Christensen
2016-03-29 15:18:09 -05:00
parent 129ff96567
commit 04e9fbcc55
7 changed files with 36 additions and 19 deletions
+20 -2
View File
@@ -20,6 +20,7 @@ import (
"time" "time"
) )
// DialFunc is a function that can be used to connect to a PostgreSQL server
type DialFunc func(network, addr string) (net.Conn, error) type DialFunc func(network, addr string) (net.Conn, error)
// ConnConfig contains all the options used to establish a connection. // ConnConfig contains all the options used to establish a connection.
@@ -67,6 +68,7 @@ type Conn struct {
poolResetCount int poolResetCount int
} }
// PreparedStatement is a description of a prepared statement
type PreparedStatement struct { type PreparedStatement struct {
Name string Name string
SQL string SQL string
@@ -74,17 +76,20 @@ type PreparedStatement struct {
ParameterOids []Oid ParameterOids []Oid
} }
// Notification is a message received from the PostgreSQL LISTEN/NOTIFY system
type Notification struct { type Notification struct {
Pid int32 // backend pid that sent the notification Pid int32 // backend pid that sent the notification
Channel string // channel from which notification was received Channel string // channel from which notification was received
Payload string Payload string
} }
// PgType is information about PostgreSQL type and how to encode and decode it
type PgType struct { type PgType struct {
Name string // name of type e.g. int4, text, date Name string // name of type e.g. int4, text, date
DefaultFormat int16 // default format (text or binary) this type will be requested in DefaultFormat int16 // default format (text or binary) this type will be requested in
} }
// CommandTag is the result of an Exec function
type CommandTag string type CommandTag string
// RowsAffected returns the number of rows affected. If the CommandTag was not // RowsAffected returns the number of rows affected. If the CommandTag was not
@@ -99,13 +104,27 @@ func (ct CommandTag) RowsAffected() int64 {
return n return n
} }
// ErrNoRows occurs when rows are expected but none are returned.
var ErrNoRows = errors.New("no rows in result set") var ErrNoRows = errors.New("no rows in result set")
// ErrNotificationTimeout occurs when WaitForNotification times out.
var ErrNotificationTimeout = errors.New("notification timeout") var ErrNotificationTimeout = errors.New("notification timeout")
// ErrDeadConn occurs on an attempt to use a dead connection
var ErrDeadConn = errors.New("conn is dead") var ErrDeadConn = errors.New("conn is dead")
// ErrTLSRefused occurs when the connection attempt requires TLS and the
// PostgreSQL server refuses to use TLS
var ErrTLSRefused = errors.New("server refused TLS connection") var ErrTLSRefused = errors.New("server refused TLS connection")
// ErrConnBusy occurs when the connection is busy (for example, in the middle of
// reading query results) and another action is attempts.
var ErrConnBusy = errors.New("conn is busy") var ErrConnBusy = errors.New("conn is busy")
// ErrInvalidLogLevel occurs on attempt to set an invalid log level.
var ErrInvalidLogLevel = errors.New("invalid log level") var ErrInvalidLogLevel = errors.New("invalid log level")
// ProtocolError occurs when unexpected data is received from PostgreSQL
type ProtocolError string type ProtocolError string
func (e ProtocolError) Error() string { func (e ProtocolError) Error() string {
@@ -790,9 +809,8 @@ func (c *Conn) CauseOfDeath() error {
func (c *Conn) sendQuery(sql string, arguments ...interface{}) (err error) { func (c *Conn) sendQuery(sql string, arguments ...interface{}) (err error) {
if ps, present := c.preparedStatements[sql]; present { if ps, present := c.preparedStatements[sql]; present {
return c.sendPreparedQuery(ps, arguments...) return c.sendPreparedQuery(ps, arguments...)
} else {
return c.sendSimpleQuery(sql, arguments...)
} }
return c.sendSimpleQuery(sql, arguments...)
} }
func (c *Conn) sendSimpleQuery(sql string, args ...interface{}) error { func (c *Conn) sendSimpleQuery(sql string, args ...interface{}) error {
+1 -2
View File
@@ -367,9 +367,8 @@ func (p *ConnPool) BeginIso(iso string) (*Tx, error) {
// again. // again.
if alive { if alive {
return nil, err return nil, err
} else {
continue
} }
continue
} }
tx.AfterClose(p.txAfterClose) tx.AfterClose(p.txAfterClose)
+1 -1
View File
@@ -30,7 +30,7 @@ type Logger interface {
Error(msg string, ctx ...interface{}) Error(msg string, ctx ...interface{})
} }
// Converts log level string to constant // LogLevelFromString converts log level string to constant
// //
// Valid levels: // Valid levels:
// trace // trace
+5 -6
View File
@@ -23,9 +23,8 @@ func (r *Row) Scan(dest ...interface{}) (err error) {
if !rows.Next() { if !rows.Next() {
if rows.Err() == nil { if rows.Err() == nil {
return ErrNoRows return ErrNoRows
} else {
return rows.Err()
} }
return rows.Err()
} }
rows.Scan(dest...) rows.Scan(dest...)
@@ -302,7 +301,7 @@ func (rows *Rows) Scan(dest ...interface{}) (err error) {
rows.Fatal(scanArgError{col: i, err: err}) rows.Fatal(scanArgError{col: i, err: err})
} }
} else if vr.Type().DataType == JsonOid || vr.Type().DataType == JsonbOid { } else if vr.Type().DataType == JsonOid || vr.Type().DataType == JsonbOid {
decodeJson(vr, &d) decodeJSON(vr, &d)
} else { } else {
if err := Decode(vr, d); err != nil { if err := Decode(vr, d); err != nil {
rows.Fatal(scanArgError{col: i, err: err}) rows.Fatal(scanArgError{col: i, err: err})
@@ -328,7 +327,7 @@ func (rows *Rows) Values() ([]interface{}, error) {
values := make([]interface{}, 0, len(rows.fields)) values := make([]interface{}, 0, len(rows.fields))
for _, _ = range rows.fields { for range rows.fields {
vr, _ := rows.nextColumn() vr, _ := rows.nextColumn()
if vr.Len() == -1 { if vr.Len() == -1 {
@@ -385,11 +384,11 @@ func (rows *Rows) Values() ([]interface{}, error) {
values = append(values, decodeInet(vr)) values = append(values, decodeInet(vr))
case JsonOid: case JsonOid:
var d interface{} var d interface{}
decodeJson(vr, &d) decodeJSON(vr, &d)
values = append(values, d) values = append(values, d)
case JsonbOid: case JsonbOid:
var d interface{} var d interface{}
decodeJson(vr, &d) decodeJSON(vr, &d)
values = append(values, d) values = append(values, d)
default: default:
rows.Fatal(errors.New("Values cannot handle binary format non-intrinsic types")) rows.Fatal(errors.New("Values cannot handle binary format non-intrinsic types"))
+4 -4
View File
@@ -47,14 +47,14 @@ func (c *Conn) BeginIso(isoLevel string) (*Tx, error) {
} }
func (c *Conn) begin(isoLevel string) (*Tx, error) { func (c *Conn) begin(isoLevel string) (*Tx, error) {
var beginSql string var beginSQL string
if isoLevel == "" { if isoLevel == "" {
beginSql = "begin" beginSQL = "begin"
} else { } else {
beginSql = fmt.Sprintf("begin isolation level %s", isoLevel) beginSQL = fmt.Sprintf("begin isolation level %s", isoLevel)
} }
_, err := c.Exec(beginSql) _, err := c.Exec(beginSQL)
if err != nil { if err != nil {
return nil, err return nil, err
} }
+1 -1
View File
@@ -37,7 +37,7 @@ func (r *ValueReader) ReadByte() byte {
return 0 return 0
} }
r.valueBytesRemaining -= 1 r.valueBytesRemaining--
if r.valueBytesRemaining < 0 { if r.valueBytesRemaining < 0 {
r.Fatal(errors.New("read past end of value")) r.Fatal(errors.New("read past end of value"))
return 0 return 0
+4 -3
View File
@@ -90,6 +90,7 @@ func init() {
} }
} }
// SerializationError occurs on failure to encode or decode a value
type SerializationError string type SerializationError string
func (e SerializationError) Error() string { func (e SerializationError) Error() string {
@@ -612,7 +613,7 @@ func Encode(wbuf *WriteBuf, oid Oid, arg interface{}) error {
} }
if oid == JsonOid || oid == JsonbOid { if oid == JsonOid || oid == JsonbOid {
return encodeJson(wbuf, oid, arg) return encodeJSON(wbuf, oid, arg)
} }
switch arg := arg.(type) { switch arg := arg.(type) {
@@ -1279,7 +1280,7 @@ func encodeByteSlice(w *WriteBuf, oid Oid, value []byte) error {
return nil return nil
} }
func decodeJson(vr *ValueReader, d interface{}) error { func decodeJSON(vr *ValueReader, d interface{}) error {
if vr.Len() == -1 { if vr.Len() == -1 {
return nil return nil
} }
@@ -1296,7 +1297,7 @@ func decodeJson(vr *ValueReader, d interface{}) error {
return err return err
} }
func encodeJson(w *WriteBuf, oid Oid, value interface{}) error { func encodeJSON(w *WriteBuf, oid Oid, value interface{}) error {
if oid != JsonOid && oid != JsonbOid { if oid != JsonOid && oid != JsonbOid {
return fmt.Errorf("cannot encode JSON into oid %v", oid) return fmt.Errorf("cannot encode JSON into oid %v", oid)
} }