refactor: a better DI-friendy logger implementation that doesn't suck
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user