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