[GODRIVER-855] when to support install by go module Created: 27/Feb/19  Updated: 07/Mar/19  Resolved: 07/Mar/19

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: 1.1.0, 1.0.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: orange.jackylee Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates GODRIVER-543 Enable support for Go 1.11 modules Closed

 Description   

when to support go modules, now install only support dep



 Comments   
Comment by orange.jackylee [ 27/Feb/19 ]

macbookpro:go_dirver fredlee$ ll
total 16K
rw-rr- 1 fredlee staff 2.4K 2 27 16:19 Gopkg.lock
rw-rr- 1 fredlee staff 741 2 27 16:19 Gopkg.toml
rw-rr- 1 fredlee staff 3.7K 2 27 16:13 main.go
rw-rr- 1 fredlee staff 1.4K 2 27 14:57 sftp-config.json
drwxr-xr-x 5 fredlee staff 160 2 27 16:19 vendor
macbookpro:go_dirver fredlee$ dep ensure -add go.mongodb.org/mongo-driver/mongo
Fetching sources...

"go.mongodb.org/mongo-driver/mongo" is not imported by your project, and has been temporarily added to Gopkg.lock and vendor/.
If you run "dep ensure" again before actually importing it, it will disappear from Gopkg.lock and vendor/.
macbookpro:go_dirver fredlee$ ll
total 16K
rw-rr- 1 fredlee staff 2.4K 2 27 16:19 Gopkg.lock
rw-rr- 1 fredlee staff 741 2 27 16:19 Gopkg.toml
rw-rr- 1 fredlee staff 3.7K 2 27 16:13 main.go
rw-rr- 1 fredlee staff 1.4K 2 27 14:57 sftp-config.json
drwxr-xr-x 5 fredlee staff 160 2 27 16:19 vendor
macbookpro:go_dirver fredlee$ go build
go: creating new go.mod: module example/db/mongo/go_dirver
go: copying requirements from Gopkg.lock
go: finding github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc
go: extracting go.mongodb.org/mongo-driver v0.3.0
go: extracting github.com/mongodb/mongo-go-driver v0.3.0
go: downloading github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc
go: extracting github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc

  1. example/db/mongo/go_dirver
    ./main.go:101:45: "go.mongodb.org/mongo-driver/mongo/options".Client().SetAppName("myapp").SetConnectTimeout(time.Second).SetSocketTimeout(time.Second).SetServerSelectionTimeout(time.Second * 3).ApplyURI undefined (type *"go.mongodb.org/mongo-driver/mongo/options".ClientOptions has no field or method ApplyURI)
    macbookpro:go_dirver fredlee$

func f3() {
clientOpts := options.Client().
SetAppName("myapp").
SetConnectTimeout(time.Second).
SetSocketTimeout(time.Second).
SetServerSelectionTimeout(time.Second * 3).
ApplyURI("mongodb://localhost:27017").
SetAuth(options.Credential

{ AuthMechanism: "SCRAM-SHA-1", AuthSource: "tips", Username: "xxx", Password: "xxxx"}

)

client, err := mongo.NewClient(clientOpts)
checkErr(err)
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
err = client.Connect(ctx)
checkErr(err)

collection := client.Database("tips").Collection("tips")
var tips []bson.M

ctx, _ = context.WithTimeout(context.Background(), 30*time.Second)
cur, err := collection.Find(ctx, bson.D{})
if err != nil

{ log.Fatal(err) }
defer cur.Close(ctx)
for cur.Next(ctx) {
var result bson.M
err := cur.Decode(&result)
if err != nil { log.Fatal(err) }
// do something with result....
tips = append(tips, result)
}
if err := cur.Err(); err != nil { log.Fatal(err) }

}

Generated at Thu Feb 08 08:35:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.