initial refactor in go

This commit is contained in:
2024-02-18 00:50:53 +02:00
parent 10dd226ab1
commit 02c85fcf28
10 changed files with 294 additions and 0 deletions

21
db_handler/db_handler.go Normal file
View 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
}