summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/lib/pq
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2017-11-13 09:09:58 -0800
committerGitHub <noreply@github.com>2017-11-13 09:09:58 -0800
commit1329aa51b605cb54ba9aae3a82a0a87b881fb7b3 (patch)
tree93cbf354ab894a560fc2cef8ef685d681b4ff889 /vendor/github.com/lib/pq
parent7304a61ef597970be3031b14e652fb3a4df44304 (diff)
downloadchat-1329aa51b605cb54ba9aae3a82a0a87b881fb7b3.tar.gz
chat-1329aa51b605cb54ba9aae3a82a0a87b881fb7b3.tar.bz2
chat-1329aa51b605cb54ba9aae3a82a0a87b881fb7b3.zip
Updating server dependancies. (#7816)
Diffstat (limited to 'vendor/github.com/lib/pq')
-rwxr-xr-xvendor/github.com/lib/pq/.travis.sh25
-rw-r--r--vendor/github.com/lib/pq/.travis.yml14
-rw-r--r--vendor/github.com/lib/pq/README.md1
-rw-r--r--vendor/github.com/lib/pq/array_test.go12
-rw-r--r--vendor/github.com/lib/pq/conn.go32
-rw-r--r--vendor/github.com/lib/pq/conn_test.go74
-rw-r--r--vendor/github.com/lib/pq/copy_test.go8
-rw-r--r--vendor/github.com/lib/pq/doc.go32
-rw-r--r--vendor/github.com/lib/pq/encode_test.go10
-rw-r--r--vendor/github.com/lib/pq/example/listen/doc.go (renamed from vendor/github.com/lib/pq/listen_example/doc.go)8
-rw-r--r--vendor/github.com/lib/pq/hstore/hstore.go2
-rw-r--r--vendor/github.com/lib/pq/notify.go56
-rw-r--r--vendor/github.com/lib/pq/notify_test.go6
13 files changed, 170 insertions, 110 deletions
diff --git a/vendor/github.com/lib/pq/.travis.sh b/vendor/github.com/lib/pq/.travis.sh
index ebf447030..ead01df73 100755
--- a/vendor/github.com/lib/pq/.travis.sh
+++ b/vendor/github.com/lib/pq/.travis.sh
@@ -70,4 +70,29 @@ postgresql_uninstall() {
sudo rm -rf /var/lib/postgresql
}
+megacheck_install() {
+ # Megacheck is Go 1.6+, so skip if Go 1.5.
+ if [[ "$(go version)" =~ "go1.5" ]]
+ then
+ echo "megacheck not supported, skipping installation"
+ return 0
+ fi
+ # Lock megacheck version at $MEGACHECK_VERSION to prevent spontaneous
+ # new error messages in old code.
+ go get -d honnef.co/go/tools/...
+ git -C $GOPATH/src/honnef.co/go/tools/ checkout $MEGACHECK_VERSION
+ go install honnef.co/go/tools/cmd/megacheck
+ megacheck --version
+}
+
+golint_install() {
+ # Golint is Go 1.6+, so skip if Go 1.5.
+ if [[ "$(go version)" =~ "go1.5" ]]
+ then
+ echo "golint not supported, skipping installation"
+ return 0
+ fi
+ go get github.com/golang/lint/golint
+}
+
$1
diff --git a/vendor/github.com/lib/pq/.travis.yml b/vendor/github.com/lib/pq/.travis.yml
index 452515c66..01468f05c 100644
--- a/vendor/github.com/lib/pq/.travis.yml
+++ b/vendor/github.com/lib/pq/.travis.yml
@@ -16,7 +16,9 @@ env:
- PQGOSSLTESTS=1
- PQSSLCERTTEST_PATH=$PWD/certs
- PGHOST=127.0.0.1
+ - MEGACHECK_VERSION=2017.1
matrix:
+ - PGVERSION=10
- PGVERSION=9.6
- PGVERSION=9.5
- PGVERSION=9.4
@@ -31,6 +33,8 @@ before_install:
- ./.travis.sh postgresql_install
- ./.travis.sh postgresql_configure
- ./.travis.sh client_configure
+ - ./.travis.sh megacheck_install
+ - ./.travis.sh golint_install
- go get golang.org/x/tools/cmd/goimports
before_script:
@@ -42,5 +46,15 @@ script:
- >
goimports -d -e $(find -name '*.go') | awk '{ print } END { exit NR == 0 ? 0 : 1 }'
- go vet ./...
+ # For compatibility with Go 1.5, launch only if megacheck is present,
+ # ignore SA1019 (deprecation warnings) in conn_test.go (we have to use the
+ # deprecated driver.Execer and driver.Queryer interfaces) and S1024
+ # (time.Until) everywhere.
+ - >
+ which megacheck > /dev/null
+ && megacheck -ignore 'github.com/lib/pq/conn_test.go:SA1019 github.com/lib/pq/*.go:S1024' ./...
+ || echo 'megacheck is not supported, skipping check'
+ # For compatibility with Go 1.5, launch only if golint is present.
+ - which golint > /dev/null && golint ./... || echo 'golint is not supported, skipping check'
- PQTEST_BINARY_PARAMETERS=no go test -race -v ./...
- PQTEST_BINARY_PARAMETERS=yes go test -race -v ./...
diff --git a/vendor/github.com/lib/pq/README.md b/vendor/github.com/lib/pq/README.md
index 7670fc87a..781c89eea 100644
--- a/vendor/github.com/lib/pq/README.md
+++ b/vendor/github.com/lib/pq/README.md
@@ -1,5 +1,6 @@
# pq - A pure Go postgres driver for Go's database/sql package
+[![GoDoc](https://godoc.org/github.com/lib/pq?status.svg)](https://godoc.org/github.com/lib/pq)
[![Build Status](https://travis-ci.org/lib/pq.svg?branch=master)](https://travis-ci.org/lib/pq)
## Install
diff --git a/vendor/github.com/lib/pq/array_test.go b/vendor/github.com/lib/pq/array_test.go
index 10b843184..f724bcd88 100644
--- a/vendor/github.com/lib/pq/array_test.go
+++ b/vendor/github.com/lib/pq/array_test.go
@@ -89,9 +89,7 @@ func TestParseArrayError(t *testing.T) {
}
func TestArrayScanner(t *testing.T) {
- var s sql.Scanner
-
- s = Array(&[]bool{})
+ var s sql.Scanner = Array(&[]bool{})
if _, ok := s.(*BoolArray); !ok {
t.Errorf("Expected *BoolArray, got %T", s)
}
@@ -126,9 +124,7 @@ func TestArrayScanner(t *testing.T) {
}
func TestArrayValuer(t *testing.T) {
- var v driver.Valuer
-
- v = Array([]bool{})
+ var v driver.Valuer = Array([]bool{})
if _, ok := v.(*BoolArray); !ok {
t.Errorf("Expected *BoolArray, got %T", v)
}
@@ -1193,9 +1189,7 @@ func TestGenericArrayValue(t *testing.T) {
}
func TestGenericArrayValueErrors(t *testing.T) {
- var v []interface{}
-
- v = []interface{}{func() {}}
+ v := []interface{}{func() {}}
if _, err := (GenericArray{v}).Value(); err == nil {
t.Errorf("Expected error for %q, got nil", v)
}
diff --git a/vendor/github.com/lib/pq/conn.go b/vendor/github.com/lib/pq/conn.go
index 338a0bc18..fadb88e5e 100644
--- a/vendor/github.com/lib/pq/conn.go
+++ b/vendor/github.com/lib/pq/conn.go
@@ -35,8 +35,12 @@ var (
errNoLastInsertID = errors.New("no LastInsertId available after the empty statement")
)
+// Driver is the Postgres database driver.
type Driver struct{}
+// Open opens a new connection to the database. name is a connection string.
+// Most users should only use it through database/sql package from the standard
+// library.
func (d *Driver) Open(name string) (driver.Conn, error) {
return Open(name)
}
@@ -78,6 +82,8 @@ func (s transactionStatus) String() string {
panic("not reached")
}
+// Dialer is the dialer interface. It can be used to obtain more control over
+// how pq creates network connections.
type Dialer interface {
Dial(network, address string) (net.Conn, error)
DialTimeout(network, address string, timeout time.Duration) (net.Conn, error)
@@ -149,11 +155,7 @@ func (cn *conn) handleDriverSettings(o values) (err error) {
if err != nil {
return err
}
- err = boolSetting("binary_parameters", &cn.binaryParameters)
- if err != nil {
- return err
- }
- return nil
+ return boolSetting("binary_parameters", &cn.binaryParameters)
}
func (cn *conn) handlePgpass(o values) {
@@ -165,11 +167,16 @@ func (cn *conn) handlePgpass(o values) {
if filename == "" {
// XXX this code doesn't work on Windows where the default filename is
// XXX %APPDATA%\postgresql\pgpass.conf
- user, err := user.Current()
- if err != nil {
- return
+ // Prefer $HOME over user.Current due to glibc bug: golang.org/issue/13470
+ userHome := os.Getenv("HOME")
+ if userHome == "" {
+ user, err := user.Current()
+ if err != nil {
+ return
+ }
+ userHome = user.HomeDir
}
- filename = filepath.Join(user.HomeDir, ".pgpass")
+ filename = filepath.Join(userHome, ".pgpass")
}
fileinfo, err := os.Stat(filename)
if err != nil {
@@ -237,10 +244,14 @@ func (cn *conn) writeBuf(b byte) *writeBuf {
}
}
+// Open opens a new connection to the database. name is a connection string.
+// Most users should only use it through database/sql package from the standard
+// library.
func Open(name string) (_ driver.Conn, err error) {
return DialOpen(defaultDialer{}, name)
}
+// DialOpen opens a new connection to the database using a dialer.
func DialOpen(d Dialer, name string) (_ driver.Conn, err error) {
// Handle any panics during connection initialization. Note that we
// specifically do *not* want to use errRecover(), as that would turn any
@@ -1431,7 +1442,8 @@ func (rs *rows) NextResultSet() error {
//
// tblname := "my_table"
// data := "my_data"
-// err = db.Exec(fmt.Sprintf("INSERT INTO %s VALUES ($1)", pq.QuoteIdentifier(tblname)), data)
+// quoted := pq.QuoteIdentifier(tblname)
+// err := db.Exec(fmt.Sprintf("INSERT INTO %s VALUES ($1)", quoted), data)
//
// Any double quotes in name will be escaped. The quoted identifier will be
// case sensitive when used in a query. If the input string contains a zero
diff --git a/vendor/github.com/lib/pq/conn_test.go b/vendor/github.com/lib/pq/conn_test.go
index d3c01f343..030a798c9 100644
--- a/vendor/github.com/lib/pq/conn_test.go
+++ b/vendor/github.com/lib/pq/conn_test.go
@@ -935,12 +935,14 @@ func TestParseErrorInExtendedQuery(t *testing.T) {
db := openTestConn(t)
defer db.Close()
- rows, err := db.Query("PARSE_ERROR $1", 1)
- if err == nil {
- t.Fatal("expected error")
+ _, err := db.Query("PARSE_ERROR $1", 1)
+ pqErr, _ := err.(*Error)
+ // Expecting a syntax error.
+ if err == nil || pqErr == nil || pqErr.Code != "42601" {
+ t.Fatalf("expected syntax error, got %s", err)
}
- rows, err = db.Query("SELECT 1")
+ rows, err := db.Query("SELECT 1")
if err != nil {
t.Fatal(err)
}
@@ -1205,16 +1207,11 @@ func TestParseComplete(t *testing.T) {
tpc("SELECT foo", "", 0, true) // invalid row count
}
-func TestExecerInterface(t *testing.T) {
- // Gin up a straw man private struct just for the type check
- cn := &conn{c: nil}
- var cni interface{} = cn
-
- _, ok := cni.(driver.Execer)
- if !ok {
- t.Fatal("Driver doesn't implement Execer")
- }
-}
+// Test interface conformance.
+var (
+ _ driver.Execer = (*conn)(nil)
+ _ driver.Queryer = (*conn)(nil)
+)
func TestNullAfterNonNull(t *testing.T) {
db := openTestConn(t)
@@ -1392,36 +1389,29 @@ func TestParseOpts(t *testing.T) {
}
func TestRuntimeParameters(t *testing.T) {
- type RuntimeTestResult int
- const (
- ResultUnknown RuntimeTestResult = iota
- ResultSuccess
- ResultError // other error
- )
-
tests := []struct {
- conninfo string
- param string
- expected string
- expectedOutcome RuntimeTestResult
+ conninfo string
+ param string
+ expected string
+ success bool
}{
// invalid parameter
- {"DOESNOTEXIST=foo", "", "", ResultError},
+ {"DOESNOTEXIST=foo", "", "", false},
// we can only work with a specific value for these two
- {"client_encoding=SQL_ASCII", "", "", ResultError},
- {"datestyle='ISO, YDM'", "", "", ResultError},
+ {"client_encoding=SQL_ASCII", "", "", false},
+ {"datestyle='ISO, YDM'", "", "", false},
// "options" should work exactly as it does in libpq
- {"options='-c search_path=pqgotest'", "search_path", "pqgotest", ResultSuccess},
+ {"options='-c search_path=pqgotest'", "search_path", "pqgotest", true},
// pq should override client_encoding in this case
- {"options='-c client_encoding=SQL_ASCII'", "client_encoding", "UTF8", ResultSuccess},
+ {"options='-c client_encoding=SQL_ASCII'", "client_encoding", "UTF8", true},
// allow client_encoding to be set explicitly
- {"client_encoding=UTF8", "client_encoding", "UTF8", ResultSuccess},
+ {"client_encoding=UTF8", "client_encoding", "UTF8", true},
// test a runtime parameter not supported by libpq
- {"work_mem='139kB'", "work_mem", "139kB", ResultSuccess},
+ {"work_mem='139kB'", "work_mem", "139kB", true},
// test fallback_application_name
- {"application_name=foo fallback_application_name=bar", "application_name", "foo", ResultSuccess},
- {"application_name='' fallback_application_name=bar", "application_name", "", ResultSuccess},
- {"fallback_application_name=bar", "application_name", "bar", ResultSuccess},
+ {"application_name=foo fallback_application_name=bar", "application_name", "foo", true},
+ {"application_name='' fallback_application_name=bar", "application_name", "", true},
+ {"fallback_application_name=bar", "application_name", "bar", true},
}
for _, test := range tests {
@@ -1436,23 +1426,23 @@ func TestRuntimeParameters(t *testing.T) {
continue
}
- tryGetParameterValue := func() (value string, outcome RuntimeTestResult) {
+ tryGetParameterValue := func() (value string, success bool) {
defer db.Close()
row := db.QueryRow("SELECT current_setting($1)", test.param)
err = row.Scan(&value)
if err != nil {
- return "", ResultError
+ return "", false
}
- return value, ResultSuccess
+ return value, true
}
- value, outcome := tryGetParameterValue()
- if outcome != test.expectedOutcome && outcome == ResultError {
+ value, success := tryGetParameterValue()
+ if success != test.success && !test.success {
t.Fatalf("%v: unexpected error: %v", test.conninfo, err)
}
- if outcome != test.expectedOutcome {
+ if success != test.success {
t.Fatalf("unexpected outcome %v (was expecting %v) for conninfo \"%s\"",
- outcome, test.expectedOutcome, test.conninfo)
+ success, test.success, test.conninfo)
}
if value != test.expected {
t.Fatalf("bad value for %s: got %s, want %s with conninfo \"%s\"",
diff --git a/vendor/github.com/lib/pq/copy_test.go b/vendor/github.com/lib/pq/copy_test.go
index 86745b38f..c1a3cd7fa 100644
--- a/vendor/github.com/lib/pq/copy_test.go
+++ b/vendor/github.com/lib/pq/copy_test.go
@@ -9,8 +9,7 @@ import (
)
func TestCopyInStmt(t *testing.T) {
- var stmt string
- stmt = CopyIn("table name")
+ stmt := CopyIn("table name")
if stmt != `COPY "table name" () FROM STDIN` {
t.Fatal(stmt)
}
@@ -27,8 +26,7 @@ func TestCopyInStmt(t *testing.T) {
}
func TestCopyInSchemaStmt(t *testing.T) {
- var stmt string
- stmt = CopyInSchema("schema name", "table name")
+ stmt := CopyInSchema("schema name", "table name")
if stmt != `COPY "schema name"."table name" () FROM STDIN` {
t.Fatal(stmt)
}
@@ -226,7 +224,7 @@ func TestCopyInTypes(t *testing.T) {
if text != "Héllö\n ☃!\r\t\\" {
t.Fatal("unexpected result", text)
}
- if bytes.Compare(blob, []byte{0, 255, 9, 10, 13}) != 0 {
+ if !bytes.Equal(blob, []byte{0, 255, 9, 10, 13}) {
t.Fatal("unexpected result", blob)
}
if nothing.Valid {
diff --git a/vendor/github.com/lib/pq/doc.go b/vendor/github.com/lib/pq/doc.go
index 6d252ecee..b2c3582c8 100644
--- a/vendor/github.com/lib/pq/doc.go
+++ b/vendor/github.com/lib/pq/doc.go
@@ -11,7 +11,8 @@ using this package directly. For example:
)
func main() {
- db, err := sql.Open("postgres", "user=pqgotest dbname=pqgotest sslmode=verify-full")
+ connStr := "user=pqgotest dbname=pqgotest sslmode=verify-full"
+ db, err := sql.Open("postgres", connStr)
if err != nil {
log.Fatal(err)
}
@@ -23,7 +24,8 @@ using this package directly. For example:
You can also connect to a database using a URL. For example:
- db, err := sql.Open("postgres", "postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full")
+ connStr := "postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full"
+ db, err := sql.Open("postgres", connStr)
Connection String Parameters
@@ -43,21 +45,28 @@ supported:
* dbname - The name of the database to connect to
* user - The user to sign in as
* password - The user's password
- * host - The host to connect to. Values that start with / are for unix domain sockets. (default is localhost)
+ * host - The host to connect to. Values that start with / are for unix
+ domain sockets. (default is localhost)
* port - The port to bind to. (default is 5432)
- * sslmode - Whether or not to use SSL (default is require, this is not the default for libpq)
+ * sslmode - Whether or not to use SSL (default is require, this is not
+ the default for libpq)
* fallback_application_name - An application_name to fall back to if one isn't provided.
- * connect_timeout - Maximum wait for connection, in seconds. Zero or not specified means wait indefinitely.
+ * connect_timeout - Maximum wait for connection, in seconds. Zero or
+ not specified means wait indefinitely.
* sslcert - Cert file location. The file must contain PEM encoded data.
* sslkey - Key file location. The file must contain PEM encoded data.
- * sslrootcert - The location of the root certificate file. The file must contain PEM encoded data.
+ * sslrootcert - The location of the root certificate file. The file
+ must contain PEM encoded data.
Valid values for sslmode are:
* disable - No SSL
* require - Always SSL (skip verification)
- * verify-ca - Always SSL (verify that the certificate presented by the server was signed by a trusted CA)
- * verify-full - Always SSL (verify that the certification presented by the server was signed by a trusted CA and the server host name matches the one in the certificate)
+ * verify-ca - Always SSL (verify that the certificate presented by the
+ server was signed by a trusted CA)
+ * verify-full - Always SSL (verify that the certification presented by
+ the server was signed by a trusted CA and the server host name
+ matches the one in the certificate)
See http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING
for more information about connection string parameters.
@@ -68,7 +77,7 @@ Use single quotes for values that contain whitespace:
A backslash will escape the next character in values:
- "user=space\ man password='it\'s valid'
+ "user=space\ man password='it\'s valid'"
Note that the connection parameter client_encoding (which sets the
text encoding for the connection) may be set but must be "UTF8",
@@ -129,7 +138,8 @@ This package returns the following types for values from the PostgreSQL backend:
- integer types smallint, integer, and bigint are returned as int64
- floating-point types real and double precision are returned as float64
- character types char, varchar, and text are returned as string
- - temporal types date, time, timetz, timestamp, and timestamptz are returned as time.Time
+ - temporal types date, time, timetz, timestamp, and timestamptz are
+ returned as time.Time
- the boolean type is returned as bool
- the bytea type is returned as []byte
@@ -229,7 +239,7 @@ for more information). Note that the channel name will be truncated to 63
bytes by the PostgreSQL server.
You can find a complete, working example of Listener usage at
-http://godoc.org/github.com/lib/pq/listen_example.
+http://godoc.org/github.com/lib/pq/examples/listen.
*/
package pq
diff --git a/vendor/github.com/lib/pq/encode_test.go b/vendor/github.com/lib/pq/encode_test.go
index 837d45bec..634a05c66 100644
--- a/vendor/github.com/lib/pq/encode_test.go
+++ b/vendor/github.com/lib/pq/encode_test.go
@@ -267,9 +267,7 @@ func TestTimestampWithOutTimezone(t *testing.T) {
t.Fatalf("Could not run query: %v", err)
}
- n := r.Next()
-
- if n != true {
+ if !r.Next() {
t.Fatal("Expected at least one row")
}
@@ -289,8 +287,7 @@ func TestTimestampWithOutTimezone(t *testing.T) {
expected, result)
}
- n = r.Next()
- if n != false {
+ if r.Next() {
t.Fatal("Expected only one row")
}
}
@@ -731,8 +728,7 @@ func TestAppendEscapedText(t *testing.T) {
}
func TestAppendEscapedTextExistingBuffer(t *testing.T) {
- var buf []byte
- buf = []byte("123\t")
+ buf := []byte("123\t")
if esc := appendEscapedText(buf, "hallo\tescape"); string(esc) != "123\thallo\\tescape" {
t.Fatal(string(esc))
}
diff --git a/vendor/github.com/lib/pq/listen_example/doc.go b/vendor/github.com/lib/pq/example/listen/doc.go
index 80f0a9b97..91e2ddbad 100644
--- a/vendor/github.com/lib/pq/listen_example/doc.go
+++ b/vendor/github.com/lib/pq/example/listen/doc.go
@@ -1,6 +1,6 @@
/*
-Below you will find a self-contained Go program which uses the LISTEN / NOTIFY
+Package listen is a self-contained Go program which uses the LISTEN / NOTIFY
mechanism to avoid polling the database while waiting for more work to arrive.
//
@@ -77,7 +77,9 @@ mechanism to avoid polling the database while waiting for more work to arrive.
}
}
- listener := pq.NewListener(conninfo, 10 * time.Second, time.Minute, reportProblem)
+ minReconn := 10 * time.Second
+ maxReconn := time.Minute
+ listener := pq.NewListener(conninfo, minReconn, maxReconn, reportProblem)
err = listener.Listen("getwork")
if err != nil {
panic(err)
@@ -93,4 +95,4 @@ mechanism to avoid polling the database while waiting for more work to arrive.
*/
-package listen_example
+package listen
diff --git a/vendor/github.com/lib/pq/hstore/hstore.go b/vendor/github.com/lib/pq/hstore/hstore.go
index 72d5abf51..f1470db14 100644
--- a/vendor/github.com/lib/pq/hstore/hstore.go
+++ b/vendor/github.com/lib/pq/hstore/hstore.go
@@ -6,7 +6,7 @@ import (
"strings"
)
-// A wrapper for transferring Hstore values back and forth easily.
+// Hstore is a wrapper for transferring Hstore values back and forth easily.
type Hstore struct {
Map map[string]sql.NullString
}
diff --git a/vendor/github.com/lib/pq/notify.go b/vendor/github.com/lib/pq/notify.go
index 09f94244b..412c6ac1e 100644
--- a/vendor/github.com/lib/pq/notify.go
+++ b/vendor/github.com/lib/pq/notify.go
@@ -60,7 +60,7 @@ type ListenerConn struct {
replyChan chan message
}
-// Creates a new ListenerConn. Use NewListener instead.
+// NewListenerConn creates a new ListenerConn. Use NewListener instead.
func NewListenerConn(name string, notificationChan chan<- *Notification) (*ListenerConn, error) {
return newDialListenerConn(defaultDialer{}, name, notificationChan)
}
@@ -214,17 +214,17 @@ func (l *ListenerConn) listenerConnMain() {
// this ListenerConn is done
}
-// Send a LISTEN query to the server. See ExecSimpleQuery.
+// Listen sends a LISTEN query to the server. See ExecSimpleQuery.
func (l *ListenerConn) Listen(channel string) (bool, error) {
return l.ExecSimpleQuery("LISTEN " + QuoteIdentifier(channel))
}
-// Send an UNLISTEN query to the server. See ExecSimpleQuery.
+// Unlisten sends an UNLISTEN query to the server. See ExecSimpleQuery.
func (l *ListenerConn) Unlisten(channel string) (bool, error) {
return l.ExecSimpleQuery("UNLISTEN " + QuoteIdentifier(channel))
}
-// Send `UNLISTEN *` to the server. See ExecSimpleQuery.
+// UnlistenAll sends an `UNLISTEN *` query to the server. See ExecSimpleQuery.
func (l *ListenerConn) UnlistenAll() (bool, error) {
return l.ExecSimpleQuery("UNLISTEN *")
}
@@ -267,8 +267,8 @@ func (l *ListenerConn) sendSimpleQuery(q string) (err error) {
return nil
}
-// Execute a "simple query" (i.e. one with no bindable parameters) on the
-// connection. The possible return values are:
+// ExecSimpleQuery executes a "simple query" (i.e. one with no bindable
+// parameters) on the connection. The possible return values are:
// 1) "executed" is true; the query was executed to completion on the
// database server. If the query failed, err will be set to the error
// returned by the database, otherwise err will be nil.
@@ -333,6 +333,7 @@ func (l *ListenerConn) ExecSimpleQuery(q string) (executed bool, err error) {
}
}
+// Close closes the connection.
func (l *ListenerConn) Close() error {
l.connectionLock.Lock()
if l.err != nil {
@@ -346,7 +347,7 @@ func (l *ListenerConn) Close() error {
return l.cn.c.Close()
}
-// Err() returns the reason the connection was closed. It is not safe to call
+// Err returns the reason the connection was closed. It is not safe to call
// this function until l.Notify has been closed.
func (l *ListenerConn) Err() error {
return l.err
@@ -354,32 +355,43 @@ func (l *ListenerConn) Err() error {
var errListenerClosed = errors.New("pq: Listener has been closed")
+// ErrChannelAlreadyOpen is returned from Listen when a channel is already
+// open.
var ErrChannelAlreadyOpen = errors.New("pq: channel is already open")
+
+// ErrChannelNotOpen is returned from Unlisten when a channel is not open.
var ErrChannelNotOpen = errors.New("pq: channel is not open")
+// ListenerEventType is an enumeration of listener event types.
type ListenerEventType int
const (
- // Emitted only when the database connection has been initially
- // initialized. err will always be nil.
+ // ListenerEventConnected is emitted only when the database connection
+ // has been initially initialized. The err argument of the callback
+ // will always be nil.
ListenerEventConnected ListenerEventType = iota
- // Emitted after a database connection has been lost, either because of an
- // error or because Close has been called. err will be set to the reason
- // the database connection was lost.
+ // ListenerEventDisconnected is emitted after a database connection has
+ // been lost, either because of an error or because Close has been
+ // called. The err argument will be set to the reason the database
+ // connection was lost.
ListenerEventDisconnected
- // Emitted after a database connection has been re-established after
- // connection loss. err will always be nil. After this event has been
- // emitted, a nil pq.Notification is sent on the Listener.Notify channel.
+ // ListenerEventReconnected is emitted after a database connection has
+ // been re-established after connection loss. The err argument of the
+ // callback will always be nil. After this event has been emitted, a
+ // nil pq.Notification is sent on the Listener.Notify channel.
ListenerEventReconnected
- // Emitted after a connection to the database was attempted, but failed.
- // err will be set to an error describing why the connection attempt did
- // not succeed.
+ // ListenerEventConnectionAttemptFailed is emitted after a connection
+ // to the database was attempted, but failed. The err argument will be
+ // set to an error describing why the connection attempt did not
+ // succeed.
ListenerEventConnectionAttemptFailed
)
+// EventCallbackType is the event callback type. See also ListenerEventType
+// constants' documentation.
type EventCallbackType func(event ListenerEventType, err error)
// Listener provides an interface for listening to notifications from a
@@ -454,9 +466,9 @@ func NewDialListener(d Dialer,
return l
}
-// Returns the notification channel for this listener. This is the same
-// channel as Notify, and will not be recreated during the life time of the
-// Listener.
+// NotificationChannel returns the notification channel for this listener.
+// This is the same channel as Notify, and will not be recreated during the
+// life time of the Listener.
func (l *Listener) NotificationChannel() <-chan *Notification {
return l.Notify
}
@@ -639,7 +651,7 @@ func (l *Listener) resync(cn *ListenerConn, notificationChan <-chan *Notificatio
// close and then return the error message from the connection, as
// per ListenerConn's interface.
if err != nil {
- for _ = range notificationChan {
+ for range notificationChan {
}
doneChan <- cn.Err()
return
diff --git a/vendor/github.com/lib/pq/notify_test.go b/vendor/github.com/lib/pq/notify_test.go
index 82a77e1eb..075666ddb 100644
--- a/vendor/github.com/lib/pq/notify_test.go
+++ b/vendor/github.com/lib/pq/notify_test.go
@@ -123,6 +123,9 @@ func TestConnUnlisten(t *testing.T) {
}
_, err = db.Exec("NOTIFY notify_test")
+ if err != nil {
+ t.Fatal(err)
+ }
err = expectNotification(t, channel, "notify_test", "")
if err != nil {
@@ -159,6 +162,9 @@ func TestConnUnlistenAll(t *testing.T) {
}
_, err = db.Exec("NOTIFY notify_test")
+ if err != nil {
+ t.Fatal(err)
+ }
err = expectNotification(t, channel, "notify_test", "")
if err != nil {