Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GODRIVER-2690 Set minimum supported Go version to 1.18 in Go Driver v2.0 #1386

Merged
merged 14 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 2 additions & 8 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ functions:
echo "crypt_shared library will be loaded from path: $CRYPT_SHARED_LIB_PATH"
fi

export GOFLAGS=-mod=vendor
AUTH="${AUTH}" \
SSL="${SSL}" \
MONGODB_URI="${MONGODB_URI}" \
Expand Down Expand Up @@ -571,7 +570,6 @@ functions:
# Per the LB testing spec, the URI of an LB fronting a single mongos should be used to configure internal
# testing Client instances, so we set MONGODB_URI to SINGLE_MONGOS_LB_URI.

export GOFLAGS=-mod=vendor
AUTH="${AUTH}" \
SSL="${SSL}" \
MONGODB_URI="${SINGLE_MONGOS_LB_URI}" \
Expand Down Expand Up @@ -1108,7 +1106,6 @@ functions:
${PREPARE_SHELL}
export KMS_TLS_TESTCASE="${KMS_TLS_TESTCASE}"

export GOFLAGS=-mod=vendor
AUTH="${AUTH}" \
SSL="${SSL}" \
MONGODB_URI="${MONGODB_URI}" \
Expand Down Expand Up @@ -1136,7 +1133,6 @@ functions:
${PREPARE_SHELL}
export KMS_MOCK_SERVERS_RUNNING="true"

export GOFLAGS=-mod=vendor
AUTH="${AUTH}" \
SSL="${SSL}" \
MONGODB_URI="${MONGODB_URI}" \
Expand Down Expand Up @@ -1923,15 +1919,13 @@ tasks:
MONGO_GO_DRIVER_COMPRESSOR: "snappy"

# Build with the oldest supported version of Go.
- name: go1.13-build
- name: go1.18-build
tags: ["compile-check"]
commands:
- func: run-make
vars:
# We only test building the compilecheck submodule with Go 1.13 because the root module's
# go.mod file contains retract directives, which are not supported until Go 1.16.
targets: "build-compile-check"
BUILD_ENV: "PATH=/opt/golang/go1.13/bin:$PATH GOROOT=/opt/golang/go1.13"
BUILD_ENV: "PATH=/opt/golang/go1.18/bin:$PATH GOROOT=/opt/golang/go1.18"

# Build with the same Go version that we're using for tests.
- name: build
Expand Down
1 change: 0 additions & 1 deletion .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export PATH="${GOROOT}/bin:${GCC_PATH}:$GOPATH/bin:$PATH"
export PROJECT="${project}"
export PKG_CONFIG_PATH=$(pwd)/install/libmongocrypt/lib64/pkgconfig:$(pwd)/install/mongo-c-driver/lib/pkgconfig
export LD_LIBRARY_PATH=$(pwd)/install/libmongocrypt/lib64
export GOFLAGS=-mod=vendor

SSL=${SSL:-nossl}
if [ "$SSL" != "nossl" -a -z "${SERVERLESS+x}" ]; then
Expand Down
16 changes: 6 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,15 @@ install-lll:
check-fmt: install-lll
etc/check_fmt.sh

# check-modules runs "go mod tidy" then "go mod vendor" and exits with a non-zero exit code if there
# are any module or vendored modules changes. The intent is to confirm two properties:
#
# 1. Exactly the required modules are declared as dependencies. We should always be able to run
# "go mod tidy" and expect that no unrelated changes are made to the "go.mod" file.
#
# 2. All required modules are copied into the vendor/ directory and are an exact copy of the
# original module source code (i.e. the vendored modules are not modified from their original code).
# check-modules runs "go mod tidy" and exits with a non-zero exit code if there
# are any module changes. The intent is to confirm that exactly the required
# modules are declared as dependencies. We should always be able to run "go mod
# tidy" and expect that no unrelated changes are made to the "go.mod" file.
.PHONY: check-modules
check-modules:
go mod tidy -v
go mod vendor
git diff --exit-code go.mod go.sum ./vendor
go mod verify
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: go mod verify seems to conflict with using Go workspaces in some cases (see golang/go#62663). When I run that command on my workstation, I get an error:

❯ go mod verify
go.mongodb.org/mongo-driver : missing ziphash: open hash: no such file or directory

Consider removing go mod verify.

git diff --exit-code go.mod go.sum

.PHONY: doc
doc:
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<p align="center"><img src="etc/assets/mongo-gopher.png" width="250"></p>
<p align="center">
<a href="https://goreportcard.com/report/go.mongodb.org/mongo-driver"><img src="https://goreportcard.com/badge/go.mongodb.org/mongo-driver"></a>
<a href="https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo"><img src="etc/assets/godev-mongo-blue.svg" alt="docs"></a>
<a href="https://pkg.go.dev/go.mongodb.org/mongo-driver/bson"><img src="etc/assets/godev-bson-blue.svg" alt="docs"></a>
<a href="https://goreportcard.com/report/go.mongodb.org/mongo-driver/v2"><img src="https://goreportcard.com/badge/go.mongodb.org/mongo-driver/v2"></a>
prestonvasquez marked this conversation as resolved.
Show resolved Hide resolved
<a href="https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/mongo"><img src="etc/assets/godev-mongo-blue.svg" alt="docs"></a>
<a href="https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson"><img src="etc/assets/godev-bson-blue.svg" alt="docs"></a>
<a href="https://www.mongodb.com/docs/drivers/go/current/"><img src="etc/assets/docs-mongodb-green.svg"></a>
</p>

Expand All @@ -22,17 +22,17 @@ The MongoDB supported driver for Go.
## Installation

The recommended way to get started using the MongoDB Go driver is by using Go modules to install the dependency in
your project. This can be done either by importing packages from `go.mongodb.org/mongo-driver` and having the build
your project. This can be done either by importing packages from `go.mongodb.org/mongo-driver/v2` and having the build
step install the dependency or by explicitly running

```bash
go get go.mongodb.org/mongo-driver/mongo
go get go.mongodb.org/mongo-driver/v2/mongo
```

When using a version of Go that does not support modules, the driver can be installed using `dep` by running

```bash
dep ensure -add "go.mongodb.org/mongo-driver/mongo"
dep ensure -add "go.mongodb.org/mongo-driver/v2/mongo"
```

-------------------------
Expand All @@ -45,9 +45,9 @@ import (
"context"
"time"

"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/mongo/readpref"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
"go.mongodb.org/mongo-driver/v2/mongo/readpref"
)

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
Expand All @@ -65,7 +65,7 @@ defer func() {
}()
```

For more advanced configuration and authentication, see the [documentation for mongo.Connect](https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Connect).
For more advanced configuration and authentication, see the [documentation for mongo.Connect](https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/mongo#Connect).

Calling `Connect` does not block for server discovery. If you wish to know if a MongoDB server has been found and connected to,
use the `Ping` method:
Expand All @@ -91,7 +91,7 @@ res, err := collection.InsertOne(ctx, bson.D{{"name", "pi"}, {"value", 3.14159}}
id := res.InsertedID
```

To use `bson.D`, you will need to add `"go.mongodb.org/mongo-driver/bson"` to your imports.
To use `bson.D`, you will need to add `"go.mongodb.org/mongo-driver/v2/bson"` to your imports.

Your import statement should now look like this:

Expand All @@ -101,10 +101,10 @@ import (
"log"
"time"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/mongo/readpref"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
"go.mongodb.org/mongo-driver/v2/mongo/readpref"
)
```

Expand Down
2 changes: 1 addition & 1 deletion benchmark/bson.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"io/ioutil"
"path/filepath"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/v2/bson"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned that doing this package major version bump now is going to make keeping v1 and master in-sync difficult for the duration of v2 development. That may cause every v1 --> master sync to hit a merge conflict or require manual modification of the import path. Is it possible to defer making the module version change until later?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this makes sense. I will revert those changes.

)

const (
Expand Down
2 changes: 1 addition & 1 deletion benchmark/bson_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"context"
"errors"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/v2/bson"
)

func bsonDocumentEncoding(tm TimerManager, iters int, source string) error {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/bson_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"errors"
"fmt"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/v2/bson"
)

func bsonMapDecoding(tm TimerManager, iters int, dataSet string) error {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/bson_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"context"
"errors"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/v2/bson"
)

func BSONFlatStructDecoding(_ context.Context, tm TimerManager, iters int) error {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/bson_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

package benchmark

import "go.mongodb.org/mongo-driver/bson/primitive"
import "go.mongodb.org/mongo-driver/v2/bson/primitive"

type flatBSONTags struct {
ID primitive.ObjectID `bson:"_id"`
Expand Down
4 changes: 2 additions & 2 deletions benchmark/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

package benchmark // import "go.mongodb.org/mongo-driver/benchmark"
package benchmark // import "go.mongodb.org/mongo-driver/v2/benchmark"

import (
"context"
"testing"
"time"

"go.mongodb.org/mongo-driver/internal/require"
"go.mongodb.org/mongo-driver/v2/internal/require"
)

const (
Expand Down
6 changes: 3 additions & 3 deletions benchmark/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"context"
"errors"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/v2/bson"
)

func MultiFindMany(ctx context.Context, tm TimerManager, iters int) error {
Expand All @@ -21,7 +21,7 @@ func MultiFindMany(ctx context.Context, tm TimerManager, iters int) error {
if err != nil {
return err
}
defer db.Client().Disconnect(ctx)
defer func() { _ = db.Client().Disconnect(ctx) }()

db = db.Client().Database("perftest")
if err = db.Drop(ctx); err != nil {
Expand Down Expand Up @@ -87,7 +87,7 @@ func multiInsertCase(ctx context.Context, tm TimerManager, iters int, data strin
if err != nil {
return err
}
defer db.Client().Disconnect(ctx)
defer func() { _ = db.Client().Disconnect(ctx) }()

db = db.Client().Database("perftest")
if err = db.Drop(ctx); err != nil {
Expand Down
12 changes: 6 additions & 6 deletions benchmark/operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"context"
"testing"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
)

var teststrings = []string{
Expand Down Expand Up @@ -41,7 +41,7 @@ func BenchmarkClientWrite(b *testing.B) {
if err != nil {
b.Fatalf("error connecting: %v", err)
}
defer client.Disconnect(context.Background())
defer func() { _ = client.Disconnect(context.Background()) }()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

golangci-lint wants us to check errors.

coll := client.Database("test").Collection("test")
_, err = coll.DeleteMany(context.Background(), bson.D{})
if err != nil {
Expand Down Expand Up @@ -85,7 +85,7 @@ func BenchmarkClientBulkWrite(b *testing.B) {
if err != nil {
b.Fatalf("error connecting: %v", err)
}
defer client.Disconnect(context.Background())
defer func() { _ = client.Disconnect(context.Background()) }()
coll := client.Database("test").Collection("test")
_, err = coll.DeleteMany(context.Background(), bson.D{})
if err != nil {
Expand Down Expand Up @@ -134,7 +134,7 @@ func BenchmarkClientRead(b *testing.B) {
if err != nil {
b.Fatalf("error connecting: %v", err)
}
defer client.Disconnect(context.Background())
defer func() { _ = client.Disconnect(context.Background()) }()
coll := client.Database("test").Collection("test")
_, err = coll.DeleteMany(context.Background(), bson.D{})
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions benchmark/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"context"
"errors"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/internal/handshake"
"go.mongodb.org/mongo-driver/internal/integtest"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/internal/handshake"
"go.mongodb.org/mongo-driver/v2/internal/integtest"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
)

const (
Expand Down Expand Up @@ -49,7 +49,7 @@ func SingleRunCommand(ctx context.Context, tm TimerManager, iters int) error {
if err != nil {
return err
}
defer db.Client().Disconnect(ctx)
defer func() { _ = db.Client().Disconnect(ctx) }()

cmd := bson.D{{handshake.LegacyHelloLowercase, true}}

Expand Down Expand Up @@ -130,7 +130,7 @@ func singleInsertCase(ctx context.Context, tm TimerManager, iters int, data stri
if err != nil {
return err
}
defer db.Client().Disconnect(ctx)
defer func() { _ = db.Client().Disconnect(ctx) }()

db = db.Client().Database("perftest")
if err = db.Drop(ctx); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions bson/bson.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
// Based on gopkg.in/mgo.v2/bson by Gustavo Niemeyer
// See THIRD-PARTY-NOTICES for original license terms.

package bson // import "go.mongodb.org/mongo-driver/bson"
package bson // import "go.mongodb.org/mongo-driver/v2/bson"

import (
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/v2/bson/primitive"
)

// Zeroer allows custom struct types to implement a report of zero
Expand Down
6 changes: 3 additions & 3 deletions bson/bson_corpus_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"unicode/utf8"

"github.com/google/go-cmp/cmp"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/internal/assert"
"go.mongodb.org/mongo-driver/internal/require"
"go.mongodb.org/mongo-driver/v2/bson/primitive"
"go.mongodb.org/mongo-driver/v2/internal/assert"
"go.mongodb.org/mongo-driver/v2/internal/require"
)

type testCase struct {
Expand Down
10 changes: 5 additions & 5 deletions bson/bson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import (
"time"

"github.com/google/go-cmp/cmp"
"go.mongodb.org/mongo-driver/bson/bsoncodec"
"go.mongodb.org/mongo-driver/bson/bsonoptions"
"go.mongodb.org/mongo-driver/bson/bsontype"
"go.mongodb.org/mongo-driver/internal/assert"
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
"go.mongodb.org/mongo-driver/v2/bson/bsoncodec"
"go.mongodb.org/mongo-driver/v2/bson/bsonoptions"
"go.mongodb.org/mongo-driver/v2/bson/bsontype"
"go.mongodb.org/mongo-driver/v2/internal/assert"
"go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore"
)

func noerr(t *testing.T, err error) {
Expand Down
4 changes: 2 additions & 2 deletions bson/bsoncodec/array_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ package bsoncodec
import (
"reflect"

"go.mongodb.org/mongo-driver/bson/bsonrw"
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
"go.mongodb.org/mongo-driver/v2/bson/bsonrw"
"go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore"
)

// ArrayCodec is the Codec used for bsoncore.Array values.
Expand Down
Loading
Loading