Skip to content

Commit

Permalink
исправлен баг в логгировании и добавлен корневой хендлер в сервере
Browse files Browse the repository at this point in the history
  • Loading branch information
xoticdsign committed Jan 2, 2025
1 parent f221eb4 commit 02edb03
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (l *Logger) WarnServer(msg string, shortyURL string, originalURL string, st

// Логгирует Error на сервере.
func (l *Logger) ErrorServer(msg string, code int) {
l.logger.Warn().
l.logger.Error().
Int("CODE", code).
Msg(msg)
}
1 change: 1 addition & 0 deletions internal/server/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func InitApp() (*fiber.App, error) {
AppName: "shortyserver",
})

app.Get("/", handlers.Root)
app.Get("/:shortyURL", handlers.Redirect)

return app, nil
Expand Down
8 changes: 8 additions & 0 deletions internal/server/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ func (d *Dependencies) OnError(c *fiber.Ctx, err error) error {
})
}

// Root хендлер.
func (d *Dependencies) Root(c *fiber.Ctx) error {
return c.JSON(models.Error{
Code: 200,
Message: "OK",
})
}

// Достает оригинальную ссылку из БД и редиректит запросы.
func (d *Dependencies) Redirect(c *fiber.Ctx) error {
start := time.Now()
Expand Down

0 comments on commit 02edb03

Please sign in to comment.