34 lines
722 B
Go
34 lines
722 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"time"
|
||
|
"fmt"
|
||
|
|
||
|
"go.mongodb.org/mongo-driver/mongo"
|
||
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||
|
// "go.mongodb.org/mongo-driver/mongo/readpref"
|
||
|
)
|
||
|
|
||
|
type Service struct {
|
||
|
id string
|
||
|
}
|
||
|
|
||
|
var client (*mongo.Client) = initDataAccess()
|
||
|
|
||
|
func initDataAccess() (*mongo.Client) {
|
||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||
|
defer cancel()
|
||
|
client, err := mongo.Connect(ctx, options.Client().ApplyURI(dbUri))
|
||
|
if err != nil {
|
||
|
fmt.Println(err)
|
||
|
Log("Error connecting to database", 4)
|
||
|
} else {
|
||
|
Log("Connected to Database", 1)
|
||
|
}
|
||
|
return client
|
||
|
}
|
||
|
|
||
|
func PutMany(collection string, data []Service) bool {
|
||
|
return false
|
||
|
}
|