MCPcopy
hub / github.com/Pradumnasaraf/DevOps / init

Function init

docs/golang/apps/mongo-api/controller/controller.go:26–37  ·  view source on GitHub ↗

Connecting with MongoDB

()

Source from the content-addressed store, hash-verified

24//Connecting with MongoDB
25
26func init() {
27 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
28 defer cancel()
29 client, err := mongo.Connect(ctx, options.Client().ApplyURI(mongoURL))
30 checkNilErr(err)
31
32 fmt.Println("MongoDB Connected sucessfully")
33
34 collection = client.Database(databaseName).Collection(collectionName)
35 fmt.Println("Collection instance is ready")
36
37}
38
39// MONGODB HELPERS
40

Callers

nothing calls this directly

Calls 1

checkNilErrFunction · 0.70

Tested by

no test coverage detected