-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
🔥 Feature: add ability to print custom message on startup #2491
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. |
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.
check my hint
I fixed that |
@Saman-Safaei can you add unit tests and update docs. Also check hooks tests if there are invalid ones |
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.
Can you take a look at the new linter warnings/errors?
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.
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