log middleware

This commit is contained in:
2025-09-29 09:14:39 +03:00
parent 49ffe9ae03
commit e15d56196d
27 changed files with 641 additions and 164 deletions

27
database/mongo.go Normal file
View File

@@ -0,0 +1,27 @@
package database
import (
"fmt"
"log"
"os"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
)
var MongoClient *mongo.Client
func ConnectMongo() {
var err error
opts := options.Client()
host, exists := os.LookupEnv("MONGO_HOST")
if !exists {
host = "localhost"
}
opts = opts.ApplyURI(fmt.Sprintf("mongodb://%s:%s@%s:27017", os.Getenv("MONGO_USER"), os.Getenv("MONGO_PASS"), host))
opts = opts.SetCompressors([]string{"snappy", "zlib", "zstd"})
MongoClient, err = mongo.Connect(opts)
if err != nil {
log.Fatalln(err)
}
}