🔥 Feature: add ability to print custom message on startup#2491
🔥 Feature: add ability to print custom message on startup#2491ReneWerner87 merged 25 commits intogofiber:masterfrom
Conversation
|
Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
|
I think it's better idea to improve onListen hook instead of adding new config |
Agree |
@efectn So, something like this? (this is just a mock-up, and does not take prefork into account) func (app *App) SetStartupMessage(fun ...func() error) {
// disable default startup message
app.config.DisableStartupMessage = true
// add each func to the onListen hook
app.hooks.onListen = append(app.hooks.onListen, fun...)
}and it allows for this: app := fiber.New()
app.SetStartupMessage(
func() error {
log.Println("Hello, ")
return nil
}, func() error {
log.Println("World!")
return nil
},
)
log.Fatal(app.Listen(":9090"))
2023/06/02 15:03:13 Hello,
2023/06/02 15:03:13 World!
^Csignal: interrupt |
Hooks handlers accept parameters as you can see here https://github.com/gofiber/fiber/blob/master/hooks.go#L8 We can pass needed variables to hook like this. However, it'll break handler signature. Perhaps we put them into a struct and pass it as variadic, so it won't break compatibility |
|
I'd recommend something like this: type ListenData struct {
Host string
Port string
TLS string
}
app.Hooks().OnListen(func(data ...ListenData) error {
if fiber.IsChild() {
return nil
}
fmt.Print(data[0].Host)
return nil
})Note: Using variadic not to break backward-compatibility. |
I fixed that |
|
@Saman-Safaei can you add unit tests and update docs. Also check hooks tests if there are invalid ones |
ghost
left a comment
There was a problem hiding this comment.
Can you take a look at the new linter warnings/errors?
ghost
left a comment
There was a problem hiding this comment.
Please revert the f98133f commit.
While the go.mod does specify go 1.20, tests still run with go 1.17-1.20, and 1.17 does not contain any yet.
|
@Saman-Safaei can you add nolint flag for a method that isTLS param is used. You can check other nolint flag usages for an example |
|
Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
add a function in listener.go to print out the developer provided custom message