fix: mongo cfg

This commit is contained in:
Samuel Tariku 2025-06-19 19:58:37 +03:00
parent 354890ece1
commit 050fe16f54
4 changed files with 8 additions and 5 deletions

View File

@ -86,7 +86,7 @@ func main() {
logger := customlogger.NewLogger(cfg.Env, cfg.LogLevel) logger := customlogger.NewLogger(cfg.Env, cfg.LogLevel)
domain.MongoDBLogger, err = mongoLogger.InitLogger() domain.MongoDBLogger, err = mongoLogger.InitLogger(cfg)
if err != nil { if err != nil {
log.Fatalf("Logger initialization failed: %v", err) log.Fatalf("Logger initialization failed: %v", err)
} }

View File

@ -4,16 +4,18 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/SamuelTariku/FortuneBet-Backend/internal/config"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"
) )
func InitLogger() (*zap.Logger, error) { func InitLogger(cfg *config.Config) (*zap.Logger, error) {
mongoCore, err := NewMongoCore( mongoCore, err := NewMongoCore(
os.Getenv("MONGODB_URL"), os.Getenv("MONGODB_URL"),
"logdb", "logdb",
"applogs", "applogs",
zapcore.InfoLevel, zapcore.InfoLevel,
cfg,
) )
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to create MongoDB core: %w", err) return nil, fmt.Errorf("failed to create MongoDB core: %w", err)

View File

@ -21,7 +21,7 @@ type MongoCore struct {
cfg *config.Config cfg *config.Config
} }
func NewMongoCore(uri, dbName, collectionName string, level zapcore.Level) (zapcore.Core, error) { func NewMongoCore(uri, dbName, collectionName string, level zapcore.Level, cfg *config.Config) (zapcore.Core, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel() defer cancel()
@ -38,6 +38,7 @@ func NewMongoCore(uri, dbName, collectionName string, level zapcore.Level) (zapc
return &MongoCore{ return &MongoCore{
collection: coll, collection: coll,
level: level, level: level,
cfg: cfg,
}, nil }, nil
} }

View File

@ -152,7 +152,7 @@ func (s *Service) GenerateTicketOutcome(ctx context.Context, eventID int64, mark
func (s *Service) CreateTicket(ctx context.Context, req domain.CreateTicketReq, clientIP string) (domain.Ticket, int64, error) { func (s *Service) CreateTicket(ctx context.Context, req domain.CreateTicketReq, clientIP string) (domain.Ticket, int64, error) {
s.mongoLogger.Info("Creating ticket") // s.mongoLogger.Info("Creating ticket")
// TODO Validate Outcomes Here and make sure they didn't expire // TODO Validate Outcomes Here and make sure they didn't expire
// Validation for creating tickets // Validation for creating tickets
if len(req.Outcomes) > 30 { if len(req.Outcomes) > 30 {