Skip to content

Commit dd34b71

Browse files
committed
Require Go 1.21
I want to use errors.Join(), which was added in Go 1.20. Might as well use 1.21 so we don't need to have our own version of slices.Contains.
1 parent 9131249 commit dd34b71

File tree

14 files changed

+39
-87
lines changed

14 files changed

+39
-87
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
fail-fast: false
3737
matrix:
3838
pg: ['14', '15', '16', '17', '18']
39-
go: ['1.18', '1.25']
39+
go: ['1.21', '1.25']
4040
steps:
4141
- uses: 'actions/checkout@v6'
4242
- uses: 'actions/setup-go@v6'

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
unreleased
22
----------
3-
This version of pq requires Go 1.18 or newer.
3+
This version of pq requires Go 1.21 or newer.
44

55
pq now supports only maintained PostgreSQL releases, which is PostgreSQL 14 and
66
newer. Previously PostgreSQL 8.4 and newer were supported.

array_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,10 @@ func TestBoolArrayValue(t *testing.T) {
337337
}
338338

339339
func BenchmarkBoolArrayValue(b *testing.B) {
340-
rand.Seed(1)
340+
rnd := rand.New(rand.NewSource(1))
341341
x := make([]bool, 10)
342342
for i := 0; i < len(x); i++ {
343-
x[i] = rand.Intn(2) == 0
343+
x[i] = rnd.Intn(2) == 0
344344
}
345345
a := BoolArray(x)
346346

@@ -488,12 +488,12 @@ func TestByteaArrayValue(t *testing.T) {
488488
}
489489

490490
func BenchmarkByteaArrayValue(b *testing.B) {
491-
rand.Seed(1)
491+
rnd := rand.New(rand.NewSource(1))
492492
x := make([][]byte, 10)
493493
for i := 0; i < len(x); i++ {
494494
x[i] = make([]byte, len(x))
495495
for j := 0; j < len(x); j++ {
496-
x[i][j] = byte(rand.Int())
496+
x[i][j] = byte(rnd.Int())
497497
}
498498
}
499499
a := ByteaArray(x)
@@ -645,10 +645,10 @@ func TestFloat64ArrayValue(t *testing.T) {
645645
}
646646

647647
func BenchmarkFloat64ArrayValue(b *testing.B) {
648-
rand.Seed(1)
648+
rnd := rand.New(rand.NewSource(1))
649649
x := make([]float64, 10)
650650
for i := 0; i < len(x); i++ {
651-
x[i] = rand.NormFloat64()
651+
x[i] = rnd.NormFloat64()
652652
}
653653
a := Float64Array(x)
654654

@@ -798,10 +798,10 @@ func TestInt64ArrayValue(t *testing.T) {
798798
}
799799

800800
func BenchmarkInt64ArrayValue(b *testing.B) {
801-
rand.Seed(1)
801+
rnd := rand.New(rand.NewSource(1))
802802
x := make([]int64, 10)
803803
for i := 0; i < len(x); i++ {
804-
x[i] = rand.Int63()
804+
x[i] = rnd.Int63()
805805
}
806806
a := Int64Array(x)
807807

@@ -952,10 +952,10 @@ func TestFloat32ArrayValue(t *testing.T) {
952952
}
953953

954954
func BenchmarkFloat32ArrayValue(b *testing.B) {
955-
rand.Seed(1)
955+
rnd := rand.New(rand.NewSource(1))
956956
x := make([]float32, 10)
957957
for i := 0; i < len(x); i++ {
958-
x[i] = rand.Float32()
958+
x[i] = rnd.Float32()
959959
}
960960
a := Float32Array(x)
961961

@@ -1105,10 +1105,10 @@ func TestInt32ArrayValue(t *testing.T) {
11051105
}
11061106

11071107
func BenchmarkInt32ArrayValue(b *testing.B) {
1108-
rand.Seed(1)
1108+
rnd := rand.New(rand.NewSource(1))
11091109
x := make([]int32, 10)
11101110
for i := 0; i < len(x); i++ {
1111-
x[i] = rand.Int31()
1111+
x[i] = rnd.Int31()
11121112
}
11131113
a := Int32Array(x)
11141114

@@ -1545,10 +1545,10 @@ func TestGenericArrayValueErrors(t *testing.T) {
15451545
}
15461546

15471547
func BenchmarkGenericArrayValueBools(b *testing.B) {
1548-
rand.Seed(1)
1548+
rnd := rand.New(rand.NewSource(1))
15491549
x := make([]bool, 10)
15501550
for i := 0; i < len(x); i++ {
1551-
x[i] = rand.Intn(2) == 0
1551+
x[i] = rnd.Intn(2) == 0
15521552
}
15531553
a := GenericArray{x}
15541554

@@ -1558,10 +1558,10 @@ func BenchmarkGenericArrayValueBools(b *testing.B) {
15581558
}
15591559

15601560
func BenchmarkGenericArrayValueFloat64s(b *testing.B) {
1561-
rand.Seed(1)
1561+
rnd := rand.New(rand.NewSource(1))
15621562
x := make([]float64, 10)
15631563
for i := 0; i < len(x); i++ {
1564-
x[i] = rand.NormFloat64()
1564+
x[i] = rnd.NormFloat64()
15651565
}
15661566
a := GenericArray{x}
15671567

@@ -1571,10 +1571,10 @@ func BenchmarkGenericArrayValueFloat64s(b *testing.B) {
15711571
}
15721572

15731573
func BenchmarkGenericArrayValueInt64s(b *testing.B) {
1574-
rand.Seed(1)
1574+
rnd := rand.New(rand.NewSource(1))
15751575
x := make([]int64, 10)
15761576
for i := 0; i < len(x); i++ {
1577-
x[i] = rand.Int63()
1577+
x[i] = rnd.Int63()
15781578
}
15791579
a := GenericArray{x}
15801580

auth/kerberos/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/lib/pq/auth/kerberos
22

3-
go 1.18
3+
go 1.21
44

55
require (
66
github.com/alexbrainman/sspi v0.0.0-20250919150558-7d374ff0d59e

connector.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111
"path/filepath"
1212
"reflect"
13+
"slices"
1314
"sort"
1415
"strconv"
1516
"strings"
@@ -516,12 +517,12 @@ func (cfg *Config) setFromTag(o map[string]string, tag string) error {
516517
}
517518
case reflect.String:
518519
if ((tag == "postgres" && k == "sslmode") || (tag == "env" && k == "PGSSLMODE")) &&
519-
!pqutil.Contains(sslModes, SSLMode(v)) &&
520+
!slices.Contains(sslModes, SSLMode(v)) &&
520521
!(strings.HasPrefix(v, "pqgo-") && hasTLSConfig(v[5:])) {
521522
return fmt.Errorf(f+`%q is not supported; supported values are %s`, k, v, pqutil.Join(sslModes))
522523
}
523524
if ((tag == "postgres" && k == "sslnegotiation") || (tag == "env" && k == "PGSSLNEGOTIATION")) &&
524-
!pqutil.Contains(sslNegotiations, SSLNegotiation(v)) {
525+
!slices.Contains(sslNegotiations, SSLNegotiation(v)) {
525526
return fmt.Errorf(f+`%q is not supported; supported values are %s`, k, v, pqutil.Join(sslNegotiations))
526527
}
527528
rv.SetString(v)
@@ -568,7 +569,7 @@ func (cfg *Config) setFromTag(o map[string]string, tag string) error {
568569
}
569570

570571
func (cfg Config) isset(name string) bool {
571-
return pqutil.Contains(cfg.set, name)
572+
return slices.Contains(cfg.set, name)
572573
}
573574

574575
// Convert to a map; mostly so we don't need to rewrite all the code.
@@ -587,7 +588,7 @@ func (cfg Config) tomap() map[string]string {
587588
if k == "" || k == "-" {
588589
continue
589590
}
590-
if !rv.IsZero() || pqutil.Contains(cfg.set, k) {
591+
if !rv.IsZero() || slices.Contains(cfg.set, k) {
591592
switch rt.Type.Kind() {
592593
default:
593594
if s, ok := rv.Interface().(fmt.Stringer); ok {

connector_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build go1.10
2-
31
package pq
42

53
import (

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/lib/pq
22

3-
go 1.18
3+
go 1.21

internal/pqtest/cert_go119.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

internal/pqtest/cert_go120.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

internal/pqtest/pqtest.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package pqtest
22

33
import (
4+
"crypto/tls"
5+
"crypto/x509"
46
"database/sql"
57
"os"
68
"strings"
@@ -40,6 +42,15 @@ func ForceBinaryParameters() bool {
4042
}
4143
}
4244

45+
// InvalidCertificate reports if this error is an "invalid certificate" error.
46+
func InvalidCertificate(err error) bool {
47+
switch err.(type) {
48+
case x509.UnknownAuthorityError, x509.HostnameError, *tls.CertificateVerificationError:
49+
return true
50+
}
51+
return false
52+
}
53+
4354
var envOnce sync.Once
4455

4556
func DSN(conninfo string) string {

0 commit comments

Comments
 (0)