initial refactor in go
This commit is contained in:
21
db_handler/db_handler.go
Normal file
21
db_handler/db_handler.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package dbhandler
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
func Connect(uri string) (*mongo.Client, error) {
|
||||
serverAPI := options.ServerAPI(options.ServerAPIVersion1)
|
||||
opts := options.Client().ApplyURI(uri).SetServerAPIOptions(serverAPI)
|
||||
|
||||
client, err := mongo.Connect(context.TODO(), opts)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
||||
Reference in New Issue
Block a user