update mongo init

This commit is contained in:
Pasha 2024-11-29 11:02:49 +03:00
parent 66b0f45a33
commit 5be2ea8cb7
4 changed files with 7 additions and 18 deletions

2
go.mod

@ -56,7 +56,7 @@ require (
)
require (
gitea.pena/PenaSide/common v0.0.0-20241126121130-cf56ae1e3fb2
gitea.pena/PenaSide/common v0.0.0-20241128160655-fe730a08b5f1
github.com/stretchr/testify v1.8.4
github.com/themakers/bdd v0.0.0-20210316111417-6b1dfe326f33
)

2
go.sum

@ -56,6 +56,8 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
gitea.pena/PenaSide/common v0.0.0-20241126121130-cf56ae1e3fb2 h1:9U9JJBwWtQV4z/PUCUWCFKurk7sHrT59fGSoXobSdL0=
gitea.pena/PenaSide/common v0.0.0-20241126121130-cf56ae1e3fb2/go.mod h1:l71j3W1yROhOSfjWZ6wcMuzjBR37gu2ZTcXsorEJoiw=
gitea.pena/PenaSide/common v0.0.0-20241128160655-fe730a08b5f1 h1:w1AAxrlZGmxUI9NAa/0TYsc6sqWWF9yAzQaLL/KxwrM=
gitea.pena/PenaSide/common v0.0.0-20241128160655-fe730a08b5f1/go.mod h1:l71j3W1yROhOSfjWZ6wcMuzjBR37gu2ZTcXsorEJoiw=
gitea.pena/PenaSide/hlog v0.0.0-20241125221102-a54c29c002a9 h1:tBkXWNIt8icmkMMnq8MA421RWkUy4OZh5P7C3q8uCu4=
gitea.pena/PenaSide/hlog v0.0.0-20241125221102-a54c29c002a9/go.mod h1:sanhSL8aEsfcq21P+eItYiAnKAre+B67nGJmDfk2cf0=
gitea.pena/PenaSide/linters-golang v0.0.0-20241119212350-2759fa93724a h1:UySqMgaOKNsR42Y6GQXoM2wn/waYNc9cakMUSvbEEAg=

@ -1,18 +1,13 @@
package initialize
import (
"gitea.pena/PenaSide/common/mongo"
"github.com/caarlos0/env/v8"
"github.com/joho/godotenv"
"log"
)
type Config struct {
MongoHost string `env:"MONGO_HOST" envDefault:"127.0.0.1"`
MongoPort string `env:"MONGO_PORT" envDefault:"27020"`
MongoUser string `env:"MONGO_USER" envDefault:"test"`
MongoPassword string `env:"MONGO_PASSWORD" envDefault:"test"`
MongoDatabase string `env:"MONGO_DB" envDefault:"admin"`
MongoAuth string `env:"MONGO_AUTH" envDefault:"admin"`
NumberPortLocal string `env:"BB_PORT" envDefault:"1488"`
AccountAddress string `env:"BB_AccountAddress" envDefault:":8931"`
LoggerDevMode bool `env:"BB_IS_PROD" envDefault:"false"`
@ -30,6 +25,7 @@ type Config struct {
TgChatID uint64 `env:"TELEGRAM_CHAT_ID" envDefault:"1001344671794"`
HTTPHost string `env:"HTTP_HOST" envDefault:"localhost"`
HTTPPort string `env:"HTTP_PORT" envDefault:"3000"`
Database mongo.Configuration
}
func LoadConfig() (*Config, error) {

@ -2,26 +2,17 @@ package initialize
import (
"context"
"go.mongodb.org/mongo-driver/mongo"
mdb "gitea.pena/PenaSide/common/mongo"
"go.mongodb.org/mongo-driver/mongo"
"time"
)
func MongoDB(ctx context.Context, cfg Config) (*mongo.Database, error) {
dbConfig := &mdb.Configuration{
Host: cfg.MongoHost,
Port: cfg.MongoPort,
User: cfg.MongoUser,
Password: cfg.MongoPassword,
DatabaseName: cfg.MongoDatabase,
Auth: cfg.MongoAuth,
}
newCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
mongoDeps := &mdb.ConnectDeps{
Configuration: dbConfig,
Configuration: &cfg.Database,
Timeout: 10 * time.Second,
}