@@ -14,6 +14,8 @@ Fiber lets you run custom callbacks at specific points in the routing lifecycle.
1414- [ OnGroup] ( #ongroup )
1515- [ OnGroupName] ( #ongroupname )
1616- [ OnListen] ( #onlisten )
17+ - [ OnPreStartupMessage/OnPostStartupMessage] ( #onprestartupmessageonpoststartupmessage )
18+ - [ ListenData] ( #listendata )
1719- [ OnFork] ( #onfork )
1820- [ OnPreShutdown] ( #onpreshutdown )
1921- [ OnPostShutdown] ( #onpostshutdown )
@@ -29,6 +31,8 @@ type OnGroupHandler = func(Group) error
2931type OnGroupNameHandler = OnGroupHandler
3032type OnListenHandler = func (ListenData) error
3133type OnForkHandler = func (int ) error
34+ type OnPreStartupMessageHandler = func (*PreStartupMessageData) error
35+ type OnPostStartupMessageHandler = func (*PostStartupMessageData) error
3236type OnPreShutdownHandler = func () error
3337type OnPostShutdownHandler = func (error ) error
3438type OnMountHandler = func (*App) error
@@ -168,6 +172,87 @@ func main() {
168172</TabItem >
169173</Tabs >
170174
175+ ## OnPreStartupMessage/OnPostStartupMessage
176+
177+ Use ` OnPreStartupMessage ` to tweak the banner before Fiber prints it, and ` OnPostStartupMessage ` to run logic after the banner is printed (or skipped). You can use some helper functions to customize the banner inside the ` OnPreStartupMessage ` hook.
178+
179+ ``` go title="Signatures"
180+ // AddInfo adds an informational entry to the startup message with "INFO" label.
181+ func (sm *PreStartupMessageData ) AddInfo (key , title , value string , priority ...int )
182+
183+ // AddWarning adds a warning entry to the startup message with "WARNING" label.
184+ func (sm *PreStartupMessageData) AddWarning(key, title, value string, priority ...int)
185+
186+ // AddError adds an error entry to the startup message with "ERROR" label.
187+ func (sm *PreStartupMessageData) AddError(key, title, value string, priority ...int)
188+
189+ // EntryKeys returns all entry keys currently present in the startup message.
190+ func (sm *PreStartupMessageData) EntryKeys() []string
191+
192+ // ResetEntries removes all existing entries from the startup message.
193+ func (sm *PreStartupMessageData) ResetEntries()
194+
195+ // DeleteEntry removes a specific entry from the startup message by its key.
196+ func (sm *PreStartupMessageData) DeleteEntry(key string)
197+ ```
198+
199+ - Assign `sm.BannerHeader` to override the ASCII art banner. Leave it empty to use the default banner provided by Fiber.
200+ - Set `sm.PreventDefault = true` to suppress the built-in banner without affecting other hooks.
201+ - `PostStartupMessageData` reports whether the banner was skipped via the `Disabled`, `IsChild`, and `Prevented` flags.
202+
203+ ```go title="Customize the startup message"
204+ package main
205+
206+ import (
207+ "fmt"
208+ "os"
209+
210+ "github.com/gofiber/fiber/v3"
211+ )
212+
213+ func main() {
214+ app := fiber.New ()
215+
216+ app.Hooks ().OnPreStartupMessage (func (sm *fiber.PreStartupMessageData ) error {
217+ sm.BannerHeader = " FOOBER " + sm.Version + " \n -------"
218+
219+ // Optional: you can also remove old entries
220+ // sm.ResetEntries()
221+
222+ sm.AddInfo (" git-hash" , " Git hash" , os.Getenv (" GIT_HASH" ))
223+ sm.AddInfo (" prefork" , " Prefork" , fmt.Sprintf (" %v " , sm.Prefork ), 15 )
224+ return nil
225+ })
226+
227+ app.Hooks ().OnPostStartupMessage (func (sm fiber.PostStartupMessageData ) error {
228+ if !sm.Disabled && !sm.IsChild && !sm.Prevented {
229+ fmt.Println (" startup completed" )
230+ }
231+ return nil
232+ })
233+
234+ app.Listen (" :5000" )
235+ }
236+ ```
237+
238+ ### ListenData
239+
240+ ` ListenData ` exposes runtime metadata about the listener:
241+
242+ | Field | Type | Description |
243+ | --- | --- | --- |
244+ | ` Host ` | ` string ` | Resolved hostname or IP address. |
245+ | ` Port ` | ` string ` | The bound port. |
246+ | ` TLS ` | ` bool ` | Indicates whether TLS is enabled. |
247+ | ` Version ` | ` string ` | Fiber version reported in the startup banner. |
248+ | ` AppName ` | ` string ` | Application name from the configuration. |
249+ | ` HandlerCount ` | ` int ` | Total registered handler count. |
250+ | ` ProcessCount ` | ` int ` | Number of processes Fiber will use. |
251+ | ` PID ` | ` int ` | Current process identifier. |
252+ | ` Prefork ` | ` bool ` | Whether prefork is enabled. |
253+ | ` ChildPIDs ` | ` []int ` | Child process identifiers when preforking. |
254+ | ` ColorScheme ` | [ ` Colors ` ] ( https://github.com/gofiber/fiber/blob/main/color.go ) | Active color scheme for the startup message. |
255+
171256## OnFork
172257
173258Runs in the child process after a fork.
0 commit comments