diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b18bf7d9..13b73f77 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/internal/pgmock/pgmock_test.go b/internal/pgmock/pgmock_test.go index bc787398..4405de2c 100644 --- a/internal/pgmock/pgmock_test.go +++ b/internal/pgmock/pgmock_test.go @@ -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, diff --git a/pgconn/config_test.go b/pgconn/config_test.go index 963455f7..1c43cdcf 100644 --- a/pgconn/config_test.go +++ b/pgconn/config_test.go @@ -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, diff --git a/pgconn/pgconn_test.go b/pgconn/pgconn_test.go index 0a2240a1..86e6f068 100644 --- a/pgconn/pgconn_test.go +++ b/pgconn/pgconn_test.go @@ -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, diff --git a/pgproto3/backend.go b/pgproto3/backend.go index 9dc0910f..6db77e4a 100644 --- a/pgproto3/backend.go +++ b/pgproto3/backend.go @@ -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. diff --git a/pgtype/tid.go b/pgtype/tid.go index cb4a9ec4..5839e874 100644 --- a/pgtype/tid.go +++ b/pgtype/tid.go @@ -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. // diff --git a/stdlib/sql.go b/stdlib/sql.go index fc0b0239..44e82d98 100644 --- a/stdlib/sql.go +++ b/stdlib/sql.go @@ -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, diff --git a/stdlib/sql_test.go b/stdlib/sql_test.go index 18591d61..314f460b 100644 --- a/stdlib/sql_test.go +++ b/stdlib/sql_test.go @@ -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