26 lines
589 B
Go
26 lines
589 B
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"queues-go/app/utils"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
var Database mongo.Database
|
|
|
|
func Connect() {
|
|
connectionString := fmt.Sprintf("mongodb://mongo:%s@%s:27017/", utils.GetEnv("MONGO_PASSWORD", "password"), utils.GetEnv("MONGO_HOST", "localhost"))
|
|
client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(connectionString))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
db := client.Database("queues")
|
|
if db == nil {
|
|
panic(fmt.Errorf("DATABASE DOES NOT EXIST"))
|
|
}
|
|
Database = *db
|
|
}
|