Apply `gofmt -s`

And add CI check for that.
pull/1490/head
Alexey Palazhchenko 2023-01-24 10:59:20 +04:00 committed by Jack Christensen
parent f581584148
commit f839d501a7
8 changed files with 69 additions and 63 deletions

View File

@ -75,7 +75,7 @@ jobs:
steps:
- name: Set up Go 1.x
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
@ -104,6 +104,12 @@ jobs:
# PGX_SSL_PASSWORD: ${{ matrix.pgx-ssl-password }}
# PGX_TEST_TLS_CLIENT_CONN_STRING: ${{ matrix.pgx-test-tls-client-conn-string }}
- name: Check formatting
run: |
gofmt -l -s -w .
git status
git diff --exit-code
- name: Test
run: go test -race ./...
env:

View File

@ -23,7 +23,7 @@ func TestScript(t *testing.T) {
script.Steps = append(script.Steps, pgmock.ExpectMessage(&pgproto3.Query{String: "select 42"}))
script.Steps = append(script.Steps, pgmock.SendMessage(&pgproto3.RowDescription{
Fields: []pgproto3.FieldDescription{
pgproto3.FieldDescription{
{
Name: []byte("?column?"),
TableOID: 0,
TableAttributeNumber: 0,

View File

@ -77,7 +77,7 @@ func TestParseConfig(t *testing.T) {
},
RuntimeParams: map[string]string{},
Fallbacks: []*pgconn.FallbackConfig{
&pgconn.FallbackConfig{
{
Host: "localhost",
Port: 5432,
TLSConfig: nil,
@ -110,7 +110,7 @@ func TestParseConfig(t *testing.T) {
TLSConfig: nil,
RuntimeParams: map[string]string{},
Fallbacks: []*pgconn.FallbackConfig{
&pgconn.FallbackConfig{
{
Host: "localhost",
Port: 5432,
TLSConfig: &tls.Config{
@ -137,7 +137,7 @@ func TestParseConfig(t *testing.T) {
},
RuntimeParams: map[string]string{},
Fallbacks: []*pgconn.FallbackConfig{
&pgconn.FallbackConfig{
{
Host: "localhost",
Port: 5432,
TLSConfig: nil,
@ -431,12 +431,12 @@ func TestParseConfig(t *testing.T) {
TLSConfig: nil,
RuntimeParams: map[string]string{},
Fallbacks: []*pgconn.FallbackConfig{
&pgconn.FallbackConfig{
{
Host: "bar",
Port: defaultPort,
TLSConfig: nil,
},
&pgconn.FallbackConfig{
{
Host: "baz",
Port: defaultPort,
TLSConfig: nil,
@ -456,12 +456,12 @@ func TestParseConfig(t *testing.T) {
TLSConfig: nil,
RuntimeParams: map[string]string{},
Fallbacks: []*pgconn.FallbackConfig{
&pgconn.FallbackConfig{
{
Host: "bar",
Port: 2,
TLSConfig: nil,
},
&pgconn.FallbackConfig{
{
Host: "baz",
Port: 3,
TLSConfig: nil,
@ -495,12 +495,12 @@ func TestParseConfig(t *testing.T) {
TLSConfig: nil,
RuntimeParams: map[string]string{},
Fallbacks: []*pgconn.FallbackConfig{
&pgconn.FallbackConfig{
{
Host: "bar",
Port: 5432,
TLSConfig: nil,
},
&pgconn.FallbackConfig{
{
Host: "baz",
Port: 5432,
TLSConfig: nil,
@ -520,12 +520,12 @@ func TestParseConfig(t *testing.T) {
TLSConfig: nil,
RuntimeParams: map[string]string{},
Fallbacks: []*pgconn.FallbackConfig{
&pgconn.FallbackConfig{
{
Host: "bar",
Port: 2,
TLSConfig: nil,
},
&pgconn.FallbackConfig{
{
Host: "baz",
Port: 3,
TLSConfig: nil,
@ -548,31 +548,31 @@ func TestParseConfig(t *testing.T) {
},
RuntimeParams: map[string]string{},
Fallbacks: []*pgconn.FallbackConfig{
&pgconn.FallbackConfig{
{
Host: "foo",
Port: defaultPort,
TLSConfig: nil,
},
&pgconn.FallbackConfig{
{
Host: "bar",
Port: defaultPort,
TLSConfig: &tls.Config{
InsecureSkipVerify: true,
ServerName: "bar",
}},
&pgconn.FallbackConfig{
{
Host: "bar",
Port: defaultPort,
TLSConfig: nil,
},
&pgconn.FallbackConfig{
{
Host: "baz",
Port: defaultPort,
TLSConfig: &tls.Config{
InsecureSkipVerify: true,
ServerName: "baz",
}},
&pgconn.FallbackConfig{
{
Host: "baz",
Port: defaultPort,
TLSConfig: nil,
@ -957,7 +957,7 @@ func TestParseConfigEnvLibpq(t *testing.T) {
},
RuntimeParams: map[string]string{},
Fallbacks: []*pgconn.FallbackConfig{
&pgconn.FallbackConfig{
{
Host: "123.123.123.123",
Port: 5432,
TLSConfig: nil,
@ -1101,7 +1101,7 @@ application_name = spaced string
},
RuntimeParams: map[string]string{},
Fallbacks: []*pgconn.FallbackConfig{
&pgconn.FallbackConfig{
{
Host: "abc.example.com",
Port: 9999,
TLSConfig: nil,
@ -1123,7 +1123,7 @@ application_name = spaced string
},
RuntimeParams: map[string]string{"application_name": "spaced string"},
Fallbacks: []*pgconn.FallbackConfig{
&pgconn.FallbackConfig{
{
Host: "def.example.com",
Port: defaultPort,
TLSConfig: nil,

View File

@ -468,7 +468,7 @@ func TestConnectWithFallback(t *testing.T) {
// Prepend current primary config to fallbacks
config.Fallbacks = append([]*pgconn.FallbackConfig{
&pgconn.FallbackConfig{
{
Host: config.Host,
Port: config.Port,
TLSConfig: config.TLSConfig,
@ -481,7 +481,7 @@ func TestConnectWithFallback(t *testing.T) {
// Prepend bad first fallback
config.Fallbacks = append([]*pgconn.FallbackConfig{
&pgconn.FallbackConfig{
{
Host: "localhost",
Port: 1,
TLSConfig: config.TLSConfig,

View File

@ -233,11 +233,11 @@ func (b *Backend) Receive() (FrontendMessage, error) {
// contextual identification of FrontendMessages. For example, in the
// PG message flow documentation for PasswordMessage:
//
// Byte1('p')
// Byte1('p')
//
// Identifies the message as a password response. Note that this is also used for
// GSSAPI, SSPI and SASL response messages. The exact message type can be deduced from
// the context.
// Identifies the message as a password response. Note that this is also used for
// GSSAPI, SSPI and SASL response messages. The exact message type can be deduced from
// the context.
//
// Since the Frontend does not know about the state of a backend, it is important
// to call SetAuthType() after an authentication request is received by the Frontend.

View File

@ -22,7 +22,7 @@ type TIDValuer interface {
//
// When one does
//
// select ctid, * from some_table;
// select ctid, * from some_table;
//
// it is the data type of the ctid hidden system column.
//

View File

@ -2,58 +2,58 @@
//
// A database/sql connection can be established through sql.Open.
//
// db, err := sql.Open("pgx", "postgres://pgx_md5:secret@localhost:5432/pgx_test?sslmode=disable")
// if err != nil {
// return err
// }
// db, err := sql.Open("pgx", "postgres://pgx_md5:secret@localhost:5432/pgx_test?sslmode=disable")
// if err != nil {
// return err
// }
//
// Or from a DSN string.
//
// db, err := sql.Open("pgx", "user=postgres password=secret host=localhost port=5432 database=pgx_test sslmode=disable")
// if err != nil {
// return err
// }
// db, err := sql.Open("pgx", "user=postgres password=secret host=localhost port=5432 database=pgx_test sslmode=disable")
// if err != nil {
// return err
// }
//
// Or a pgx.ConnConfig can be used to set configuration not accessible via connection string. In this case the
// pgx.ConnConfig must first be registered with the driver. This registration returns a connection string which is used
// with sql.Open.
//
// connConfig, _ := pgx.ParseConfig(os.Getenv("DATABASE_URL"))
// connConfig.Logger = myLogger
// connStr := stdlib.RegisterConnConfig(connConfig)
// db, _ := sql.Open("pgx", connStr)
// connConfig, _ := pgx.ParseConfig(os.Getenv("DATABASE_URL"))
// connConfig.Logger = myLogger
// connStr := stdlib.RegisterConnConfig(connConfig)
// db, _ := sql.Open("pgx", connStr)
//
// pgx uses standard PostgreSQL positional parameters in queries. e.g. $1, $2. It does not support named parameters.
//
// db.QueryRow("select * from users where id=$1", userID)
// db.QueryRow("select * from users where id=$1", userID)
//
// (*sql.Conn) Raw() can be used to get a *pgx.Conn from the standard database/sql.DB connection pool. This allows
// operations that use pgx specific functionality.
//
// // Given db is a *sql.DB
// conn, err := db.Conn(context.Background())
// if err != nil {
// // handle error from acquiring connection from DB pool
// }
// // Given db is a *sql.DB
// conn, err := db.Conn(context.Background())
// if err != nil {
// // handle error from acquiring connection from DB pool
// }
//
// err = conn.Raw(func(driverConn any) error {
// conn := driverConn.(*stdlib.Conn).Conn() // conn is a *pgx.Conn
// // Do pgx specific stuff with conn
// conn.CopyFrom(...)
// return nil
// })
// if err != nil {
// // handle error that occurred while using *pgx.Conn
// }
// err = conn.Raw(func(driverConn any) error {
// conn := driverConn.(*stdlib.Conn).Conn() // conn is a *pgx.Conn
// // Do pgx specific stuff with conn
// conn.CopyFrom(...)
// return nil
// })
// if err != nil {
// // handle error that occurred while using *pgx.Conn
// }
//
// PostgreSQL Specific Data Types
// # PostgreSQL Specific Data Types
//
// The pgtype package provides support for PostgreSQL specific types. *pgtype.Map.SQLScanner is an adapter that makes
// these types usable as a sql.Scanner.
//
// m := pgtype.NewMap()
// var a []int64
// err := db.QueryRow("select '{1,2,3}'::bigint[]").Scan(m.SQLScanner(&a))
// m := pgtype.NewMap()
// var a []int64
// err := db.QueryRow("select '{1,2,3}'::bigint[]").Scan(m.SQLScanner(&a))
package stdlib
import (
@ -140,7 +140,7 @@ func RandomizeHostOrderFunc(ctx context.Context, connConfig *pgx.ConnConfig) err
return nil
}
newFallbacks := append([]*pgconn.FallbackConfig{&pgconn.FallbackConfig{
newFallbacks := append([]*pgconn.FallbackConfig{{
Host: connConfig.Host,
Port: connConfig.Port,
TLSConfig: connConfig.TLSConfig,

View File

@ -1105,9 +1105,9 @@ func TestRandomizeHostOrderFunc(t *testing.T) {
// Test that at some point we connect to all 3 hosts
hostsNotSeenYet := map[string]struct{}{
"host1": struct{}{},
"host2": struct{}{},
"host3": struct{}{},
"host1": {},
"host2": {},
"host3": {},
}
// If we don't succeed within this many iterations, something is certainly wrong