You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add lifecycle hook support and documentation for server shutdown
- Add lifecycle hook support with WithBeforeShutdown and WithAfterShutdown options for registering custom logic before and after graceful server shutdown.
- Document lifecycle hooks usage, execution order, and sample code in all README files with examples in English, Simplified Chinese, and Traditional Chinese.
- Create a complete example under _examples/hooks demonstrating lifecycle hook usage, expected output, and use cases.
- Validate that lifecycle hook options reject nil functions and handle hook errors properly.
- Test lifecycle hook execution order, error handling, and context cancellation in the shutdown process.
Signed-off-by: appleboy <appleboy.tw@gmail.com>
Register a hook to be called before server shutdown begins. Multiple hooks can be registered and will execute in registration order. Hooks receive the shutdown context and can return errors, which are collected but do not prevent shutdown from proceeding.
160
+
161
+
-**WithAfterShutdown(hook Hook)**:
162
+
Register a hook to be called after all servers have shut down. Multiple hooks can be registered and will execute in registration order. Hooks receive the shutdown context and can return errors, which are collected and returned but do not affect server shutdown.
Lifecycle hooks allow you to execute custom logic during graceful shutdown. Use `WithBeforeShutdown` for cleanup that should happen before servers stop (like deregistering from service discovery), and `WithAfterShutdown` for cleanup after servers have stopped (like closing database connections).
0 commit comments