-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
✨ feature: add callShutdownHooksOnSigInt function #1834
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
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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
package fiber | ||
|
||
import "os" | ||
|
||
// Handlers define a function to create hooks for Fiber. | ||
type error | ||
type > | ||
type error | ||
type > | ||
type error | ||
type class="x x-first x-last">OnListenHandler | ||
type class="x x-first x-last">func(*os.Signal) | ||
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. This would break backwards compatibility :(. Honestly I think not showing 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. I think we can add DisableDefaultGraceful config instead. Otherwise, i dont think hardcoded things are good. What about? @ReneWerner87 @hi019 @Streamer272 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. Sure, works for me. What's hardcoded, though? 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.
Some users may want to add their custom signals. |
||
|
||
type hooks struct { | ||
// Embed app | ||
|
@@ -76,7 +78,7 @@ func (h *hooks) OnListen(handler ...OnListenHandler) { | |
h.app.mutex.Unlock() | ||
} | ||
|
||
// OnShutdown is a hook to execute user functions after Shutdown. | ||
// OnShutdown is a hook to execute user functions before Shutdown. | ||
func (h *hooks) OnShutdown(handler ...OnShutdownHandler) { | ||
h.app.mutex.Lock() | ||
h. handler...) | ||
|
@@ -94,7 +96,6 @@ func (h *hooks) executeOnRouteHooks(route Route) error { | |
} | ||
|
||
func (h *hooks) executeOnNameHooks(route Route) error { | ||
|
||
for _, v := range h.onName { | ||
if err := v(route); err != nil { | ||
return err | ||
|
@@ -134,8 +135,8 @@ func (h *hooks) executeOnListenHooks() error { | |
return nil | ||
} | ||
|
||
func (h *hooks) executeOnShutdownHooks() { | ||
func (h *hooks) executeOnShutdownHooks(signal *os.Signal) { | ||
for _, v := range h.onShutdown { | ||
_ = v() | ||
v(signal) | ||
} | ||
} |
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 believe that we need to give autonomy to the people to treat signals according to their needs it.
Maybe we can create a method to explicit this signals default.
I created a package treat signals Golang maybe it can help you.
https://github.com/renanbastos93/ossignals