initial
This commit is contained in:
25
app/storage/mongo/client.go
Normal file
25
app/storage/mongo/client.go
Normal file
@@ -0,0 +1,25 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user