Skip to content

Commit

Permalink
chore(api): logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Apr 18, 2024
1 parent d5c918d commit a136a3f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 4 additions & 1 deletion internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (
"github.com/gotd/td/telegram"
"github.com/gotd/td/telegram/message/peer"
"github.com/ogen-go/ogen/http"
"go.uber.org/zap"

"github.com/go-faster/bot/internal/ent"
"github.com/go-faster/bot/internal/oas"
)

func NewServer(db *ent.Client, tg *telegram.Client, resolver peer.Resolver, ht http.Client) *Server {
func NewServer(lg *zap.Logger, db *ent.Client, tg *telegram.Client, resolver peer.Resolver, ht http.Client) *Server {
return &Server{
lg: lg,
db: db,
tg: tg,
ht: ht,
Expand All @@ -25,6 +27,7 @@ type Server struct {
tg *telegram.Client
ht http.Client
resolver peer.Resolver
lg *zap.Logger
}

func (s Server) NewError(ctx context.Context, err error) *oas.ErrorStatusCode {
Expand Down
5 changes: 2 additions & 3 deletions internal/api/badge.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"strings"

"github.com/go-faster/errors"
"github.com/go-faster/sdk/zctx"
"github.com/gotd/td/tg"
"go.uber.org/zap"

Expand Down Expand Up @@ -50,7 +49,7 @@ func (s Server) GetTelegramBadge(ctx context.Context, params oas.GetTelegramBadg
if err != nil {
return nil, errors.Wrap(err, "get chat")
}
zctx.From(ctx).Info("Got chat",
s.lg.Info("Got chat",
zap.Int("chats", len(fullChat.Chats)),
zap.Int64("id", fullChat.FullChat.(*tg.ChatFull).ID),
zap.String("about", fullChat.FullChat.(*tg.ChatFull).About),
Expand All @@ -62,7 +61,7 @@ func (s Server) GetTelegramBadge(ctx context.Context, params oas.GetTelegramBadg
case *tg.Channel:
members = c.ParticipantsCount
default:
zctx.From(ctx).Warn("unexpected chat type",
s.lg.Warn("unexpected chat type",
zap.String("type", fmt.Sprintf("%T", chat)),
)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/internal/server/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (a *App) Run(ctx context.Context) error {
httpClient := &http.Client{
Transport: a.httpTransport,
}
h, err := oas.NewServer(api.NewServer(a.db, a.client, a.resolver, httpClient),
h, err := oas.NewServer(api.NewServer(lg, a.db, a.client, a.resolver, httpClient),
oas.WithMeterProvider(a.m.MeterProvider()),
oas.WithTracerProvider(a.m.TracerProvider()),
)
Expand Down

0 comments on commit a136a3f

Please sign in to comment.