Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1325,16 +1325,14 @@ func (app *App) serverErrorHandler(fctx *fasthttp.RequestCtx, err error) {
}

// startupProcess Is the method which executes all the necessary processes just before the start of the server.
func (app *App) startupProcess() *App {
func (app *App) startupProcess() {
app.mutex.Lock()
defer app.mutex.Unlock()

app.mountStartupProcess()

// build route tree stack
app.buildTree()

return app
}

// Run onListen hooks. If they return an error, panic.
Expand Down
58 changes: 58 additions & 0 deletions docs/api/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,64 @@ func main() {
</TabItem>
</Tabs>

### ListenData

`ListenData` exposes runtime metadata about the listener:

| Field | Type | Description |
| --- | --- | --- |
| `Host` | `string` | Resolved hostname or IP address. |
| `Port` | `string` | The bound port. |
| `TLS` | `bool` | Indicates whether TLS is enabled. |
| `Version` | `string` | Fiber version reported in the startup banner. |
| `AppName` | `string` | Application name from the configuration. |
| `HandlerCount` | `int` | Total registered handler count. |
| `ProcessCount` | `int` | Number of processes Fiber will use. |
| `PID` | `int` | Current process identifier. |
| `Prefork` | `bool` | Whether prefork is enabled. |
| `ChildPIDs` | `[]int` | Child process identifiers when preforking. |
| `ColorScheme` | [`Colors`](https://github.com/gofiber/fiber/blob/main/color.go) | Active color scheme for the startup message. |

### Startup message customization

Use `OnPreStartupMessage` to tweak the banner before Fiber prints it, and `OnPostStartupMessage` to run logic after the banner is printed (or skipped):

- Assign `sm.Header` to override the ASCII art banner. Leave it empty to use the default.
- Provide `sm.PrimaryInfo` and/or `sm.SecondaryInfo` maps to replace the primary (server URL, handler counts, etc.) and secondary (prefork status, PID, process count) sections.
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

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

The documentation incorrectly describes PrimaryInfo and SecondaryInfo fields that don't exist. The actual API uses methods AddInfo(), AddWarning(), AddError(), ResetEntries(), and DeleteEntry() to manage startup entries. Update this documentation to reflect the actual implementation.

Copilot uses AI. Check for mistakes.
- Set `sm.PreventDefault = true` to suppress the built-in banner without affecting other hooks.
- `PostStartupMessageData` reports whether the banner was skipped via the `Disabled`, `IsChild`, and `Prevented` flags.

```go title="Customize the startup message"
package main

import (
"fmt"
"os"

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

func main() {
app := fiber.New()

app.Hooks().OnPreStartupMessage(func(sm *fiber.PreStartupMessageData) error {
sm.Header = "FOOBER " + sm.Version + "\n-------"
sm.PrimaryInfo = fiber.Map{"Git hash": os.Getenv("GIT_HASH")}
sm.SecondaryInfo = fiber.Map{"Prefork": sm.Prefork}
Comment on lines +213 to +214
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

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

The example code references non-existent fields. Replace with the actual API methods: sm.AddInfo(\"git_hash\", \"Git hash\", os.Getenv(\"GIT_HASH\"), priority) and similar calls for other entries.

Suggested change
sm.PrimaryInfo = fiber.Map{"Git hash": os.Getenv("GIT_HASH")}
sm.SecondaryInfo = fiber.Map{"Prefork": sm.Prefork}
sm.AddInfo("git_hash", "Git hash", os.Getenv("GIT_HASH"), fiber.InfoPrimary)
sm.AddInfo("prefork", "Prefork", sm.Prefork, fiber.InfoSecondary)

Copilot uses AI. Check for mistakes.
return nil
})

app.Hooks().OnPostStartupMessage(func(sm fiber.PostStartupMessageData) error {
if !sm.Disabled && !sm.IsChild && !sm.Prevented {
fmt.Println("startup completed")
}
return nil
})

app.Listen(":5000")
}
```
Comment on lines +193 to +227
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The documentation for startup message customization is outdated. The description mentions sm.PrimaryInfo and sm.SecondaryInfo, and the example code uses them, but these fields do not exist on the PreStartupMessageData struct. The new API uses methods like AddInfo, AddWarning, and AddError. The documentation and example should be updated to reflect the correct API usage, as shown in the pull request description.

- Use `sm.AddInfo()`, `sm.AddWarning()`, and `sm.AddError()` to add, update, or remove startup message entries.
- Assign `sm.Header` to override the ASCII art banner. Leave it empty to use the default.
- Set `sm.PreventDefault = true` to suppress the built-in banner without affecting other hooks.
- `PostStartupMessageData` reports whether the banner was skipped via the `Disabled`, `IsChild`, and `Prevented` flags.

```go title="Customize the startup message"
package main

import (
	"fmt"

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

func main() {
	app := fiber.New()

	app.Hooks().OnPreStartupMessage(func(sm *fiber.PreStartupMessageData) error {
		sm.Header = "My Awesome App v" + sm.Version + "\n----------------------"
		// You can add custom info, warnings, or errors to the startup message.
		sm.AddInfo("custom_info", "Custom Info", "This is a custom message.")
		sm.AddWarning("custom_warning", "Custom Warning", "This is a custom warning.")
		// Entries can be prioritized. Higher priority entries are shown first.
		sm.AddError("custom_error", "Custom Error", "This is a custom error.", 10)
		return nil
	})

	app.Hooks().OnPostStartupMessage(func(sm fiber.PostStartupMessageData) error {
		if !sm.Disabled && !sm.IsChild && !sm.Prevented {
			fmt.Println("startup completed")
		}
		return nil
	})

	app.Listen(":5000")
}

Comment on lines +171 to +227
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Docs: correct startup customization API usage

Replace references to PrimaryInfo/SecondaryInfo with the provided entry APIs and adjust the example.

-Use `OnPreStartupMessage` to tweak the banner before Fiber prints it, and `OnPostStartupMessage` to run logic after the banner is printed (or skipped):
-
-- Assign `sm.Header` to override the ASCII art banner. Leave it empty to use the default.
-- Provide `sm.PrimaryInfo` and/or `sm.SecondaryInfo` maps to replace the primary (server URL, handler counts, etc.) and secondary (prefork status, PID, process count) sections.
-- Set `sm.PreventDefault = true` to suppress the built-in banner without affecting other hooks.
-- `PostStartupMessageData` reports whether the banner was skipped via the `Disabled`, `IsChild`, and `Prevented` flags.
+Use `OnPreStartupMessage` to tweak the banner before Fiber prints it, and `OnPostStartupMessage` to run logic after the banner is printed (or skipped):
+
+- Set `sm.Header` to override the ASCII art/banner. Leave empty to keep the default.
+- Add lines with `sm.AddInfo`, `sm.AddWarning`, or `sm.AddError`. Use the optional `priority` arg to influence ordering (higher priority first).
+- Set `sm.PreventDefault = true` to suppress the built‑in banner.
+- `PostStartupMessageData` reports if the banner was disabled, printed by a child, or prevented via `Disabled`, `IsChild`, and `Prevented`.
@@
-    app.Hooks().OnPreStartupMessage(func(sm *fiber.PreStartupMessageData) error {
-        sm.Header = "FOOBER " + sm.Version + "\n-------"
-        sm.PrimaryInfo = fiber.Map{"Git hash": os.Getenv("GIT_HASH")}
-        sm.SecondaryInfo = fiber.Map{"Prefork": sm.Prefork}
-        return nil
-    })
+    app.Hooks().OnPreStartupMessage(func(sm *fiber.PreStartupMessageData) error {
+        sm.Header = "FOOBER " + sm.Version + "\n-------"
+        sm.AddInfo("git_hash", "Git hash", os.Getenv("GIT_HASH"))
+        sm.AddInfo("prefork", "Prefork", fmt.Sprint(sm.Prefork))
+        return nil
+    })
@@
-        if !sm.Disabled && !sm.IsChild && !sm.Prevented {
-            fmt.Println("startup completed")
-        }
+        if !sm.Disabled && !sm.IsChild && !sm.Prevented {
+            fmt.Println("startup completed")
+        }
         return nil
     })

Optionally document entry ordering/priority briefly.

🤖 Prompt for AI Agents
In docs/api/hooks.md around lines 171–227, the startup customization example and
description still reference sm.PrimaryInfo and sm.SecondaryInfo which are
incorrect; update the prose and code sample to use the hook's provided entry
APIs (e.g. call the API methods to add primary and secondary entries instead of
assigning maps), adjust the example to show calling those entry methods to set a
"Git hash" primary entry and a "Prefork" secondary entry, and optionally add one
short sentence noting that entries are rendered in the order they are added
(earlier entries have higher display priority).


## OnFork

Runs in the child process after a fork.
Expand Down
23 changes: 23 additions & 0 deletions docs/whats_new.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,29 @@ app.Listen("app.sock", fiber.ListenerConfig{
})
```

- Expanded `ListenData` with versioning, handler, process, and PID metadata, plus dedicated startup message hooks for customization.

```go
app := fiber.New()

app.Hooks().OnPreStartupMessage(func(sm *fiber.PreStartupMessageData) error {
sm.Header = "FOOBER " + sm.Version + "\n-------"
sm.PrimaryInfo = fiber.Map{"Git hash": os.Getenv("GIT_HASH")}
sm.SecondaryInfo = fiber.Map{"Process count": sm.ProcessCount}
Comment on lines +305 to +306
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

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

The documentation references PrimaryInfo and SecondaryInfo fields that do not exist in the PreStartupMessageData struct. According to the actual implementation in hooks.go, users should call methods like AddInfo(), AddWarning(), AddError(), ResetEntries(), and DeleteEntry() to customize the startup entries. Update the example to use the correct API: sm.AddInfo(key, title, value, priority).

Suggested change
sm.PrimaryInfo = fiber.Map{"Git hash": os.Getenv("GIT_HASH")}
sm.SecondaryInfo = fiber.Map{"Process count": sm.ProcessCount}
sm.AddInfo("git_hash", "Git hash", os.Getenv("GIT_HASH"), fiber.PriorityHigh)
sm.AddInfo("process_count", "Process count", sm.ProcessCount, fiber.PriorityLow)

Copilot uses AI. Check for mistakes.
// Set sm.PreventDefault = true to suppress the default banner entirely.
return nil
})
Comment on lines +303 to +309
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The example code for the new startup message hooks uses sm.PrimaryInfo and sm.SecondaryInfo, which are from an older implementation and no longer exist on PreStartupMessageData. The new API uses methods like AddInfo. This example should be updated to reflect the correct usage.

Suggested change
app.Hooks().OnPreStartupMessage(func(sm *fiber.PreStartupMessageData) error {
sm.Header = "FOOBER " + sm.Version + "\n-------"
sm.PrimaryInfo = fiber.Map{"Git hash": os.Getenv("GIT_HASH")}
sm.SecondaryInfo = fiber.Map{"Process count": sm.ProcessCount}
// Set sm.PreventDefault = true to suppress the default banner entirely.
return nil
})
app.Hooks().OnPreStartupMessage(func(sm *fiber.PreStartupMessageData) error {
sm.Header = "FOOBER " + sm.Version + "\n-------"
sm.AddInfo("git_hash", "Git hash", os.Getenv("GIT_HASH"))
sm.AddInfo("process_count", "Process count", fmt.Sprintf("%d", sm.ProcessCount))
// Set sm.PreventDefault = true to suppress the default banner entirely.
return nil
})


app.Hooks().OnPostStartupMessage(func(sm fiber.PostStartupMessageData) error {
if !sm.Disabled && !sm.IsChild && !sm.Prevented {
log.Println("startup completed")
}
return nil
})

go app.Listen(":3000")
```
Comment on lines +298 to +319
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Align example with actual API (no PrimaryInfo/SecondaryInfo fields)

PreStartupMessageData exposes AddInfo/AddWarning/AddError and Header/PreventDefault, not PrimaryInfo/SecondaryInfo. Update the snippet to compile and reflect the API.

 app := fiber.New()
 
 app.Hooks().OnPreStartupMessage(func(sm *fiber.PreStartupMessageData) error {
-    sm.Header = "FOOBER " + sm.Version + "\n-------"
-    sm.PrimaryInfo = fiber.Map{"Git hash": os.Getenv("GIT_HASH")}
-    sm.SecondaryInfo = fiber.Map{"Process count": sm.ProcessCount}
+    sm.Header = "FOOBER " + sm.Version + "\n-------"
+    sm.AddInfo("git_hash", "Git hash", os.Getenv("GIT_HASH"))
+    sm.AddInfo("proc_count", "Process count", fmt.Sprint(sm.ProcessCount))
     // Set sm.PreventDefault = true to suppress the default banner entirely.
     return nil
 })
 
 app.Hooks().OnPostStartupMessage(func(sm fiber.PostStartupMessageData) error {
     if !sm.Disabled && !sm.IsChild && !sm.Prevented {
-        log.Println("startup completed")
+        fmt.Println("startup completed")
     }
     return nil
 })
 
 go app.Listen(":3000")
🤖 Prompt for AI Agents
In docs/whats_new.md around lines 298 to 319, the PreStartupMessageData example
uses nonexistent PrimaryInfo/SecondaryInfo fields and will not compile; replace
those with calls to AddInfo/AddWarning/AddError and set Header/PreventDefault as
shown by the API, e.g. populate the metadata using sm.AddInfo(key, value) (or
AddWarning/AddError) and remove PrimaryInfo/SecondaryInfo assignments, and
ensure the PostStartupMessageData checks use the actual fields
(Disabled/IsChild/Prevented) as in the snippet so the example matches the real
API.


## 🗺 Router

We have slightly adapted our router interface
Expand Down
217 changes: 213 additions & 4 deletions hooks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package fiber

import (
"fmt"
"sort"

"github.com/gofiber/fiber/v3/log"
)

Expand All @@ -15,6 +18,10 @@
OnGroupNameHandler = OnGroupHandler
// OnListenHandler runs when the application begins listening and receives the listener details.
OnListenHandler = func(ListenData) error
// OnPreStartupMessageHandler runs before Fiber prints the startup banner.
OnPreStartupMessageHandler = func(*PreStartupMessageData) error
// OnPostStartupMessageHandler runs after Fiber prints (or skips) the startup banner.
OnPostStartupMessageHandler = func(PostStartupMessageData) error
// OnPreShutdownHandler runs before the application shuts down.
OnPreShutdownHandler = func() error
// OnPostShutdownHandler runs after shutdown and receives the shutdown result.
Expand All @@ -36,17 +43,183 @@
onGroup []OnGroupHandler
onGroupName []OnGroupNameHandler
onListen []OnListenHandler
onPreStartup []OnPreStartupMessageHandler
onPostStartup []OnPostStartupMessageHandler
onPreShutdown []OnPreShutdownHandler
onPostShutdown []OnPostShutdownHandler
onFork []OnForkHandler
onMount []OnMountHandler
}

// ListenData is a struct to use it with OnListenHandler
type StartupMessageLevel int

const (
// StartupMessageLevelInfo represents informational startup message entries.
StartupMessageLevelInfo StartupMessageLevel = iota
// StartupMessageLevelWarning represents warning startup message entries.
StartupMessageLevelWarning
// StartupMessageLevelError represents error startup message entries.
StartupMessageLevelError
)

// startupMessageEntry represents a single line of startup message information.
type startupMessageEntry struct {
key string
title string
value string
priority int
level StartupMessageLevel
}

// ListenData contains the listener metadata provided to OnListenHandler.
type ListenData struct {
Host string
Port string
TLS bool
ColorScheme Colors
Host string
Port string
Version string
AppName string

ChildPIDs []int

HandlerCount int
ProcessCount int
PID int

TLS bool
Prefork bool
}

// PreStartupMessageData contains metadata exposed to OnPreStartupMessage hooks.
type PreStartupMessageData struct {

Check failure on line 93 in hooks.go

View workflow job for this annotation

GitHub Actions / lint

fieldalignment: struct with 40 pointer bytes could be 32 (govet)
*ListenData

entries []startupMessageEntry

Header string

PreventDefault bool
}
Comment on lines +93 to +101
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Fix struct field alignment for PreStartupMessageData

Govet/betteralign flags padding waste. Reorder fields to reduce padding and satisfy the pipeline.

-type PreStartupMessageData struct {
-	*ListenData
-	entries []startupMessageEntry
-	Header string
-	PreventDefault bool
-}
+type PreStartupMessageData struct {
+	*ListenData
+	Header        string
+	entries       []startupMessageEntry
+	PreventDefault bool
+}

As per coding guidelines (betteralign).

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
type PreStartupMessageData struct {
*ListenData
entries []startupMessageEntry
Header string
PreventDefault bool
}
type PreStartupMessageData struct {
*ListenData
Header string
entries []startupMessageEntry
PreventDefault bool
}
🧰 Tools
🪛 GitHub Actions: golangci-lint

[error] 93-93: golangci-lint (go vet) error: fieldalignment: struct with 40 pointer bytes could be 32 (govet)

🪛 GitHub Check: lint

[failure] 93-93:
fieldalignment: struct with 40 pointer bytes could be 32 (govet)

🤖 Prompt for AI Agents
In hooks.go around lines 93 to 101, reorder the PreStartupMessageData struct
fields to eliminate padding waste: place the largest-aligned fields first
(entries slice), then Header (string), then the *ListenData pointer, and finally
PreventDefault (bool). Update the struct field order to: entries, Header,
*ListenData, PreventDefault and run go vet/go test to verify alignment fixes.


func (sm *PreStartupMessageData) AddInfo(key, title, value string, priority ...int) {
pri := -1
if len(priority) > 0 {
pri = priority[0]
}

sm.addEntry(key, title, value, pri, StartupMessageLevelInfo)
}

func (sm *PreStartupMessageData) AddWarning(key, title, value string, priority ...int) {
pri := -1
if len(priority) > 0 {
pri = priority[0]
}

sm.addEntry(key, title, value, pri, StartupMessageLevelWarning)
}

func (sm *PreStartupMessageData) AddError(key, title, value string, priority ...int) {
pri := -1
if len(priority) > 0 {
pri = priority[0]
}

sm.addEntry(key, title, value, pri, StartupMessageLevelError)
}

func (sm *PreStartupMessageData) EntryKeys() []string {
keys := make([]string, 0, len(sm.entries))
for _, entry := range sm.entries {
keys = append(keys, entry.key)
}
return keys
}

func (sm *PreStartupMessageData) ResetEntries() {
sm.entries = sm.entries[:0]
}

func (sm *PreStartupMessageData) addEntry(key, title, value string, priority int, level StartupMessageLevel) {
if sm.entries == nil {
sm.entries = make([]startupMessageEntry, 0)
}

for i, entry := range sm.entries {
if entry.key == key {
sm.entries[i].value = value
sm.entries[i].title = title
sm.entries[i].level = level
sm.entries[i].priority = priority
return
}
}

sm.entries = append(sm.entries, startupMessageEntry{key: key, title: title, value: value, level: level, priority: priority})
}

func (sm *PreStartupMessageData) DeleteEntry(key string) {
if sm.entries == nil {
return
}

for i, entry := range sm.entries {
if entry.key == key {
sm.entries = append(sm.entries[:i], sm.entries[i+1:]...)
return
}
}
}

func newPreStartupMessageData(listenData ListenData) *PreStartupMessageData {
clone := listenData
if len(listenData.ChildPIDs) > 0 {
clone.ChildPIDs = append([]int(nil), listenData.ChildPIDs...)
}

return &PreStartupMessageData{ListenData: &clone}
}

// PostStartupMessageData contains metadata exposed to OnPostStartupMessage hooks.
type PostStartupMessageData struct {
*ListenData

Disabled bool
IsChild bool
Prevented bool
}

func newPostStartupMessageData(listenData ListenData, disabled, isChild, prevented bool) PostStartupMessageData {
clone := listenData
if len(listenData.ChildPIDs) > 0 {
clone.ChildPIDs = append([]int(nil), listenData.ChildPIDs...)
}

return PostStartupMessageData{
ListenData: &clone,
Disabled: disabled,
IsChild: isChild,
Prevented: prevented,
}
}

func mapToEntries(values Map) ([]startupMessageEntry, bool) {

Check failure on line 205 in hooks.go

View workflow job for this annotation

GitHub Actions / lint

func mapToEntries is unused (unused)
if len(values) == 0 {
return nil, false
}

keys := make([]string, 0, len(values))
for key := range values {
keys = append(keys, key)
}

sort.Strings(keys)

entries := make([]startupMessageEntry, 0, len(values))
for _, key := range keys {
entries = append(entries, startupMessageEntry{key: key, value: fmt.Sprint(values[key])})
}

return entries, true
}
Comment on lines +205 to 223
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The function mapToEntries appears to be dead code. It's not called anywhere in the codebase. It seems like a leftover from a previous implementation that used PrimaryInfo and SecondaryInfo maps. It should be removed to keep the code clean.

Comment on lines +205 to 223
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Remove or silence unused mapToEntries to fix lint failure

mapToEntries is unused and breaks CI. Either remove it now or add a targeted nolint with rationale.

Option A (remove):

-func mapToEntries(values Map) ([]startupMessageEntry, bool) {
-	if len(values) == 0 {
-		return nil, false
-	}
-	keys := make([]string, 0, len(values))
-	for key := range values {
-		keys = append(keys, key)
-	}
-	sort.Strings(keys)
-	entries := make([]startupMessageEntry, 0, len(values))
-	for _, key := range keys {
-		entries = append(entries, startupMessageEntry{key: key, value: fmt.Sprint(values[key])})
-	}
-	return entries, true
-}

Option B (silence temporarily):

- func mapToEntries(values Map) ([]startupMessageEntry, bool) {
+ // mapToEntries converts a map to sorted entries.
+ // nolint:unused // Will be wired by listen.go banner mapping follow-up.
+ func mapToEntries(values Map) ([]startupMessageEntry, bool) {

Choose A if no immediate use is planned. As per coding guidelines.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func mapToEntries(values Map) ([]startupMessageEntry, bool) {
if len(values) == 0 {
return nil, false
}
keys := make([]string, 0, len(values))
for key := range values {
keys = append(keys, key)
}
sort.Strings(keys)
entries := make([]startupMessageEntry, 0, len(values))
for _, key := range keys {
entries = append(entries, startupMessageEntry{key: key, value: fmt.Sprint(values[key])})
}
return entries, true
}
🧰 Tools
🪛 GitHub Check: lint

[failure] 205-205:
func mapToEntries is unused (unused)

🤖 Prompt for AI Agents
In hooks.go around lines 205 to 223, the helper function mapToEntries is
currently unused and causing CI lint failures; either delete the entire function
if it is not needed, or if you expect to use it imminently add a targeted nolint
(e.g., //nolint:unused // keep for upcoming startupMessage refactor) immediately
above the function and include a one‑sentence rationale, then run linters to
confirm the failure is resolved.


func newHooks(app *App) *Hooks {
Expand All @@ -57,6 +230,8 @@
onGroupName: make([]OnGroupNameHandler, 0),
onName: make([]OnNameHandler, 0),
onListen: make([]OnListenHandler, 0),
onPreStartup: make([]OnPreStartupMessageHandler, 0),
onPostStartup: make([]OnPostStartupMessageHandler, 0),
onPreShutdown: make([]OnPreShutdownHandler, 0),
onPostShutdown: make([]OnPostShutdownHandler, 0),
onFork: make([]OnForkHandler, 0),
Expand Down Expand Up @@ -107,6 +282,20 @@
h.app.mutex.Unlock()
}

// OnPreStartupMessage is a hook to execute user functions before the startup message is printed.
func (h *Hooks) OnPreStartupMessage(handler ...OnPreStartupMessageHandler) {
h.app.mutex.Lock()
h.onPreStartup = append(h.onPreStartup, handler...)
h.app.mutex.Unlock()
}

// OnPostStartupMessage is a hook to execute user functions after the startup message is printed (or skipped).
func (h *Hooks) OnPostStartupMessage(handler ...OnPostStartupMessageHandler) {
h.app.mutex.Lock()
h.onPostStartup = append(h.onPostStartup, handler...)
h.app.mutex.Unlock()
}

// OnPreShutdown is a hook to execute user functions before Shutdown.
func (h *Hooks) OnPreShutdown(handler ...OnPreShutdownHandler) {
h.app.mutex.Lock()
Expand Down Expand Up @@ -209,6 +398,26 @@
return nil
}

func (h *Hooks) executeOnPreStartupMessageHooks(data *PreStartupMessageData) error {
for _, handler := range h.onPreStartup {
if err := handler(data); err != nil {
return err
}
}

return nil
}

func (h *Hooks) executeOnPostStartupMessageHooks(data PostStartupMessageData) error {
for _, handler := range h.onPostStartup {
if err := handler(data); err != nil {
return err
}
}

return nil
}

func (h *Hooks) executeOnPreShutdownHooks() {
for _, v := range h.onPreShutdown {
if err := v(); err != nil {
Expand Down
Loading
Loading