Skip to content

Commit b299316

Browse files
committed
Fix some linting issues
1 parent dd1fe20 commit b299316

File tree

5 files changed

+61
-64
lines changed

5 files changed

+61
-64
lines changed

array.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
var typeByteSlice = reflect.TypeOf([]byte{})
1515
var typeDriverValuer = reflect.TypeOf((*driver.Valuer)(nil)).Elem()
16-
var typeSqlScanner = reflect.TypeOf((*sql.Scanner)(nil)).Elem()
16+
var typeSQLScanner = reflect.TypeOf((*sql.Scanner)(nil)).Elem()
1717

1818
// Array returns the optimal driver.Valuer and sql.Scanner for an array or
1919
// slice of any dimension.
@@ -278,7 +278,7 @@ func (GenericArray) evaluateDestination(rt reflect.Type) (reflect.Type, func([]b
278278
// TODO calculate the assign function for other types
279279
// TODO repeat this section on the element type of arrays or slices (multidimensional)
280280
{
281-
if reflect.PtrTo(rt).Implements(typeSqlScanner) {
281+
if reflect.PtrTo(rt).Implements(typeSQLScanner) {
282282
// dest is always addressable because it is an element of a slice.
283283
assign = func(src []byte, dest reflect.Value) (err error) {
284284
ss := dest.Addr().Interface().(sql.Scanner)
@@ -587,7 +587,7 @@ func appendArrayElement(b []byte, rv reflect.Value) ([]byte, string, error) {
587587
}
588588
}
589589

590-
var del string = ","
590+
var del = ","
591591
var err error
592592
var iv interface{} = rv.Interface()
593593

conn.go

+40-43
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ var (
2727
ErrNotSupported = errors.New("pq: Unsupported command")
2828
ErrInFailedTransaction = errors.New("pq: Could not complete operation in a failed transaction")
2929
ErrSSLNotSupported = errors.New("pq: SSL is not enabled on the server")
30-
ErrSSLKeyHasWorldPermissions = errors.New("pq: Private key file has group or world access. Permissions should be u=rw (0600) or less.")
31-
ErrCouldNotDetectUsername = errors.New("pq: Could not detect default username. Please provide one explicitly.")
30+
ErrSSLKeyHasWorldPermissions = errors.New("pq: Private key file has group or world access. Permissions should be u=rw (0600) or less")
31+
ErrCouldNotDetectUsername = errors.New("pq: Could not detect default username. Please provide one explicitly")
3232

3333
errUnexpectedReady = errors.New("unexpected ReadyForQuery")
3434
errNoRowsAffected = errors.New("no RowsAffected available after the empty statement")
35-
errNoLastInsertId = errors.New("no LastInsertId available after the empty statement")
35+
errNoLastInsertID = errors.New("no LastInsertId available after the empty statement")
3636
)
3737

3838
type Driver struct{}
@@ -131,7 +131,7 @@ type conn struct {
131131
}
132132

133133
// Handle driver-side settings in parsed connection string.
134-
func (c *conn) handleDriverSettings(o values) (err error) {
134+
func (cn *conn) handleDriverSettings(o values) (err error) {
135135
boolSetting := func(key string, val *bool) error {
136136
if value, ok := o[key]; ok {
137137
if value == "yes" {
@@ -145,18 +145,18 @@ func (c *conn) handleDriverSettings(o values) (err error) {
145145
return nil
146146
}
147147

148-
err = boolSetting("disable_prepared_binary_result", &c.disablePreparedBinaryResult)
148+
err = boolSetting("disable_prepared_binary_result", &cn.disablePreparedBinaryResult)
149149
if err != nil {
150150
return err
151151
}
152-
err = boolSetting("binary_parameters", &c.binaryParameters)
152+
err = boolSetting("binary_parameters", &cn.binaryParameters)
153153
if err != nil {
154154
return err
155155
}
156156
return nil
157157
}
158158

159-
func (c *conn) handlePgpass(o values) {
159+
func (cn *conn) handlePgpass(o values) {
160160
// if a password was supplied, do not process .pgpass
161161
if _, ok := o["password"]; ok {
162162
return
@@ -229,10 +229,10 @@ func (c *conn) handlePgpass(o values) {
229229
}
230230
}
231231

232-
func (c *conn) writeBuf(b byte) *writeBuf {
233-
c.scratch[0] = b
232+
func (cn *conn) writeBuf(b byte) *writeBuf {
233+
cn.scratch[0] = b
234234
return &writeBuf{
235-
buf: c.scratch[:5],
235+
buf: cn.scratch[:5],
236236
pos: 1,
237237
}
238238
}
@@ -310,9 +310,8 @@ func DialOpen(d Dialer, name string) (_ driver.Conn, err error) {
310310
u, err := userCurrent()
311311
if err != nil {
312312
return nil, err
313-
} else {
314-
o["user"] = u
315313
}
314+
o["user"] = u
316315
}
317316

318317
cn := &conn{
@@ -698,7 +697,7 @@ var emptyRows noRows
698697
var _ driver.Result = noRows{}
699698

700699
func (noRows) LastInsertId() (int64, error) {
701-
return 0, errNoLastInsertId
700+
return 0, errNoLastInsertID
702701
}
703702

704703
func (noRows) RowsAffected() (int64, error) {
@@ -840,16 +839,15 @@ func (cn *conn) query(query string, args []driver.Value) (_ *rows, err error) {
840839
rows.colNames, rows.colFmts, rows.colTyps = cn.readPortalDescribeResponse()
841840
cn.postExecuteWorkaround()
842841
return rows, nil
843-
} else {
844-
st := cn.prepareTo(query, "")
845-
st.exec(args)
846-
return &rows{
847-
cn: cn,
848-
colNames: st.colNames,
849-
colTyps: st.colTyps,
850-
colFmts: st.colFmts,
851-
}, nil
852842
}
843+
st := cn.prepareTo(query, "")
844+
st.exec(args)
845+
return &rows{
846+
cn: cn,
847+
colNames: st.colNames,
848+
colTyps: st.colTyps,
849+
colFmts: st.colFmts,
850+
}, nil
853851
}
854852

855853
// Implement the optional "Execer" interface for one-shot queries
@@ -876,17 +874,16 @@ func (cn *conn) Exec(query string, args []driver.Value) (res driver.Result, err
876874
cn.postExecuteWorkaround()
877875
res, _, err = cn.readExecuteResponse("Execute")
878876
return res, err
879-
} else {
880-
// Use the unnamed statement to defer planning until bind
881-
// time, or else value-based selectivity estimates cannot be
882-
// used.
883-
st := cn.prepareTo(query, "")
884-
r, err := st.Exec(args)
885-
if err != nil {
886-
panic(err)
887-
}
888-
return r, err
889877
}
878+
// Use the unnamed statement to defer planning until bind
879+
// time, or else value-based selectivity estimates cannot be
880+
// used.
881+
st := cn.prepareTo(query, "")
882+
r, err := st.Exec(args)
883+
if err != nil {
884+
panic(err)
885+
}
886+
return r, err
890887
}
891888

892889
func (cn *conn) send(m *writeBuf) {
@@ -1147,10 +1144,10 @@ const formatText format = 0
11471144
const formatBinary format = 1
11481145

11491146
// One result-column format code with the value 1 (i.e. all binary).
1150-
var colFmtDataAllBinary []byte = []byte{0, 1, 0, 1}
1147+
var colFmtDataAllBinary = []byte{0, 1, 0, 1}
11511148

11521149
// No result-column format codes (i.e. all text).
1153-
var colFmtDataAllText []byte = []byte{0, 0}
1150+
var colFmtDataAllText = []byte{0, 0}
11541151

11551152
type stmt struct {
11561153
cn *conn
@@ -1515,7 +1512,7 @@ func (cn *conn) sendBinaryModeQuery(query string, args []driver.Value) {
15151512
cn.send(b)
15161513
}
15171514

1518-
func (c *conn) processParameterStatus(r *readBuf) {
1515+
func (cn *conn) processParameterStatus(r *readBuf) {
15191516
var err error
15201517

15211518
param := r.string()
@@ -1526,22 +1523,22 @@ func (c *conn) processParameterStatus(r *readBuf) {
15261523
var minor int
15271524
_, err = fmt.Sscanf(r.string(), "%d.%d.%d", &major1, &major2, &minor)
15281525
if err == nil {
1529-
c.parameterStatus.serverVersion = major1*10000 + major2*100 + minor
1526+
cn.parameterStatus.serverVersion = major1*10000 + major2*100 + minor
15301527
}
15311528

15321529
case "TimeZone":
1533-
c.parameterStatus.currentLocation, err = time.LoadLocation(r.string())
1530+
cn.parameterStatus.currentLocation, err = time.LoadLocation(r.string())
15341531
if err != nil {
1535-
c.parameterStatus.currentLocation = nil
1532+
cn.parameterStatus.currentLocation = nil
15361533
}
15371534

15381535
default:
15391536
// ignore
15401537
}
15411538
}
15421539

1543-
func (c *conn) processReadyForQuery(r *readBuf) {
1544-
c.txnStatus = transactionStatus(r.byte())
1540+
func (cn *conn) processReadyForQuery(r *readBuf) {
1541+
cn.txnStatus = transactionStatus(r.byte())
15451542
}
15461543

15471544
func (cn *conn) readReadyForQuery() {
@@ -1556,9 +1553,9 @@ func (cn *conn) readReadyForQuery() {
15561553
}
15571554
}
15581555

1559-
func (c *conn) processBackendKeyData(r *readBuf) {
1560-
c.processID = r.int32()
1561-
c.secretKey = r.int32()
1556+
func (cn *conn) processBackendKeyData(r *readBuf) {
1557+
cn.processID = r.int32()
1558+
cn.secretKey = r.int32()
15621559
}
15631560

15641561
func (cn *conn) readParseResponse() {

conn_test.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func TestOpenURL(t *testing.T) {
136136
testURL("postgresql://")
137137
}
138138

139-
const pgpass_file = "/tmp/pqgotest_pgpass"
139+
const pgpassFile = "/tmp/pqgotest_pgpass"
140140

141141
func TestPgpass(t *testing.T) {
142142
if os.Getenv("TRAVIS") != "true" {
@@ -172,10 +172,10 @@ func TestPgpass(t *testing.T) {
172172
txn.Rollback()
173173
}
174174
testAssert("", "ok", "missing .pgpass, unexpected error %#v")
175-
os.Setenv("PGPASSFILE", pgpass_file)
175+
os.Setenv("PGPASSFILE", pgpassFile)
176176
testAssert("host=/tmp", "fail", ", unexpected error %#v")
177-
os.Remove(pgpass_file)
178-
pgpass, err := os.OpenFile(pgpass_file, os.O_RDWR|os.O_CREATE, 0644)
177+
os.Remove(pgpassFile)
178+
pgpass, err := os.OpenFile(pgpassFile, os.O_RDWR|os.O_CREATE, 0644)
179179
if err != nil {
180180
t.Fatalf("Unexpected error writing pgpass file %#v", err)
181181
}
@@ -213,15 +213,15 @@ localhost:*:*:*:pass_C
213213
// wrong permissions for the pgpass file means it should be ignored
214214
assertPassword(values{"host": "example.com", "user": "foo"}, "")
215215
// fix the permissions and check if it has taken effect
216-
os.Chmod(pgpass_file, 0600)
216+
os.Chmod(pgpassFile, 0600)
217217
assertPassword(values{"host": "server", "dbname": "some_db", "user": "some_user"}, "pass_A")
218218
assertPassword(values{"host": "example.com", "user": "foo"}, "pass_fallback")
219219
assertPassword(values{"host": "example.com", "dbname": "some_db", "user": "some_user"}, "pass_B")
220220
// localhost also matches the default "" and UNIX sockets
221221
assertPassword(values{"host": "", "user": "some_user"}, "pass_C")
222222
assertPassword(values{"host": "/tmp", "user": "some_user"}, "pass_C")
223223
// cleanup
224-
os.Remove(pgpass_file)
224+
os.Remove(pgpassFile)
225225
os.Setenv("PGPASSFILE", "")
226226
}
227227

@@ -393,8 +393,8 @@ func TestEmptyQuery(t *testing.T) {
393393
if _, err := res.RowsAffected(); err != errNoRowsAffected {
394394
t.Fatalf("expected %s, got %v", errNoRowsAffected, err)
395395
}
396-
if _, err := res.LastInsertId(); err != errNoLastInsertId {
397-
t.Fatalf("expected %s, got %v", errNoLastInsertId, err)
396+
if _, err := res.LastInsertId(); err != errNoLastInsertID {
397+
t.Fatalf("expected %s, got %v", errNoLastInsertID, err)
398398
}
399399
rows, err := db.Query("")
400400
if err != nil {
@@ -425,8 +425,8 @@ func TestEmptyQuery(t *testing.T) {
425425
if _, err := res.RowsAffected(); err != errNoRowsAffected {
426426
t.Fatalf("expected %s, got %v", errNoRowsAffected, err)
427427
}
428-
if _, err := res.LastInsertId(); err != errNoLastInsertId {
429-
t.Fatalf("expected %s, got %v", errNoLastInsertId, err)
428+
if _, err := res.LastInsertId(); err != errNoLastInsertID {
429+
t.Fatalf("expected %s, got %v", errNoLastInsertID, err)
430430
}
431431
rows, err = stmt.Query()
432432
if err != nil {
@@ -1053,16 +1053,16 @@ func TestIssue282(t *testing.T) {
10531053
db := openTestConn(t)
10541054
defer db.Close()
10551055

1056-
var search_path string
1056+
var searchPath string
10571057
err := db.QueryRow(`
10581058
SET LOCAL search_path TO pg_catalog;
10591059
SET LOCAL search_path TO pg_catalog;
1060-
SHOW search_path`).Scan(&search_path)
1060+
SHOW search_path`).Scan(&searchPath)
10611061
if err != nil {
10621062
t.Fatal(err)
10631063
}
1064-
if search_path != "pg_catalog" {
1065-
t.Fatalf("unexpected search_path %s", search_path)
1064+
if searchPath != "pg_catalog" {
1065+
t.Fatalf("unexpected search_path %s", searchPath)
10661066
}
10671067
}
10681068

encode_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -370,17 +370,17 @@ func TestInfinityTimestamp(t *testing.T) {
370370
t.Errorf("Scanning -infinity, expected time %q, got %q", y1500, resultT.String())
371371
}
372372

373-
y_1500 := time.Date(-1500, time.January, 1, 0, 0, 0, 0, time.UTC)
373+
ym1500 := time.Date(-1500, time.January, 1, 0, 0, 0, 0, time.UTC)
374374
y11500 := time.Date(11500, time.January, 1, 0, 0, 0, 0, time.UTC)
375375
var s string
376-
err = db.QueryRow("SELECT $1::timestamp::text", y_1500).Scan(&s)
376+
err = db.QueryRow("SELECT $1::timestamp::text", ym1500).Scan(&s)
377377
if err != nil {
378378
t.Errorf("Encoding -infinity, expected no error, got %q", err)
379379
}
380380
if s != "-infinity" {
381381
t.Errorf("Encoding -infinity, expected %q, got %q", "-infinity", s)
382382
}
383-
err = db.QueryRow("SELECT $1::timestamptz::text", y_1500).Scan(&s)
383+
err = db.QueryRow("SELECT $1::timestamptz::text", ym1500).Scan(&s)
384384
if err != nil {
385385
t.Errorf("Encoding -infinity, expected no error, got %q", err)
386386
}

uuid_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestDecodeUUIDBackend(t *testing.T) {
3333
db := openTestConn(t)
3434
defer db.Close()
3535

36-
var s string = "a0ecc91d-a13f-4fe4-9fce-7e09777cc70a"
36+
var s = "a0ecc91d-a13f-4fe4-9fce-7e09777cc70a"
3737
var scanned interface{}
3838

3939
err := db.QueryRow(`SELECT $1::uuid`, s).Scan(&scanned)

0 commit comments

Comments
 (0)