init
This commit is contained in:
24
db/db.go
Normal file
24
db/db.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
var (
|
||||
Client *mongo.Client
|
||||
UserCollection, Vclusters_details *mongo.Collection
|
||||
)
|
||||
|
||||
func InitDB() {
|
||||
clientOptions := options.Client().ApplyURI("mongodb://root:example@192.168.1.10:27017/")
|
||||
client, err := mongo.Connect(context.TODO(), clientOptions)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
UserCollection = client.Database("vcluster").Collection("users")
|
||||
}
|
||||
Reference in New Issue
Block a user