Refactoring

1. Move all pre-defined messages to constants in a separate file
2. Remove pkg/errors dependency
This commit is contained in:
2025-05-15 22:20:37 +03:00
parent 0a8409e66d
commit 9e38b000ec
10 changed files with 34 additions and 20 deletions
@@ -1,39 +0,0 @@
package middleware
import (
"context"
"fmt"
"github.com/nightnoryu/anon3anon/pkg/infrastructure/jsonlog"
"github.com/go-telegram/bot"
"github.com/go-telegram/bot/models"
)
const (
chatIDField = "chat_id"
usernameField = "username"
)
func NewLoggingMiddleware(logger jsonlog.Logger) bot.Middleware {
return func(next bot.HandlerFunc) bot.HandlerFunc {
return func(ctx context.Context, bot *bot.Bot, update *models.Update) {
if update.Message == nil {
return
}
chatLogger := logger.
WithField(chatIDField, update.Message.Chat.ID).
WithField(usernameField, update.Message.From.Username)
text := update.Message.Text
if len(update.Message.Caption) > 0 {
text = update.Message.Caption
}
chatLogger.Info(fmt.Sprintf("new message: %s", text))
next(ctx, bot, update)
}
}
}