Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚸 Add log middleware to basic template #124

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,20 @@ var (
newBasicTemplate = `package main

import (
"log"
"github.com/gofiber/fiber/v2/middleware/logger"

"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2"
)

func main() {
app := fiber.New()
app := fiber.New()
app.Use(logger.New())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does add overhead, probably why the default server doesnt have it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is useful to have it, maybe i can add a check for a env like "DEBUG" and activate only when the enviroment is develop?


app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World!")
})
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World!")
})

log.Fatal(app.Listen(":3000"))
app.Listen(":3000")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for the server startup

The app.Listen() call should include error handling to prevent silent failures.

Here's the suggested improvement:

-	app.Listen(":3000")
+	if err := app.Listen(":3000"); err != nil {
+		log.Fatal(err)
+	}

Don't forget to add the log package to the imports:

+	"log"

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log fatal is needed else you won't see why it failed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ops, i forgot xd

}`

newSuccessTemplate = `
Expand Down