refactor: a better DI-friendy logger implementation that doesn't suck

This commit is contained in:
2025-06-23 14:18:25 +03:00
parent ea3743cb04
commit 1b55498b00
3 changed files with 35 additions and 29 deletions

View File

@@ -3,7 +3,6 @@ package services
import (
"easywish/internal/database"
errs "easywish/internal/errors"
"easywish/internal/logger"
"easywish/internal/models"
"easywish/internal/utils"
@@ -18,11 +17,11 @@ type AuthService interface {
}
type authServiceImpl struct {
log logger.Logger
log *zap.Logger
dbctx database.DbContext
}
func NewAuthService(_log logger.Logger, _dbctx database.DbContext) AuthService {
func NewAuthService(_log *zap.Logger, _dbctx database.DbContext) AuthService {
return &authServiceImpl{log: _log, dbctx: _dbctx}
}
@@ -33,10 +32,10 @@ func (a *authServiceImpl) RegistrationBegin(request models.RegistrationBeginRequ
user, err := db.TXQueries.CreateUser(db.CTX, request.Username) // TODO: validation
if err != nil {
a.log.Get().Error("Failed to add user to database", zap.Error(err))
a.log.Error("Failed to add user to database", zap.Error(err))
return false, errs.ErrServerError
}
a.log.Get().Info("Registered a new user", zap.String("username", user.Username))
a.log.Info("Registered a new user", zap.String("username", user.Username))
helper.Commit()