-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()) | ||
|
||
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling for the server startup The 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"
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ops, i forgot xd |
||
}` | ||
|
||
newSuccessTemplate = ` | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?