package
Version:
v1.5.0
Opens a new window with list of versions in this module.
Published: Sep 18, 2026
License: Apache-2.0
Opens a new window with license information.
Imports: 7
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
Documentation
¶
Init 按注册顺序执行全部已注册的初始化函数并清空注册表,
任一失败立即停止后续执行并返回该错误,不自动执行已注册的解构函数。
func OnDeinit[F lifecycleFunc](fn F)
OnDeinit 注册解构函数,由 Wait 按注册逆序执行;带 context.Context 参数时传入 context.Background()。
func OnInit[F lifecycleFunc](fn F)
OnInit 注册初始化函数,由 Init 按注册顺序执行;带 context.Context 参数时传入 context.Background()。
Shutdown 主动触发退出,reason 作为 Wait 的返回值;重复调用无效。
Wait 阻塞等待 SIGINT/SIGTERM 信号或 Shutdown 触发退出,
然后按注册逆序执行全部解构函数;解构函数自身的错误经默认 slog 记录,不影响其余解构执行。
信号触发视为正常退出返回 nil,主动退出返回 Shutdown 携带的原因;
解构期间再次收到退出信号时跳过剩余解构强制退出,避免解构卡死导致进程无法终止。
Source Files
¶
Click to show internal directories.
Click to hide internal directories.