Documentation
¶
Overview ¶
Package shutdownx 优雅退出编排工具。提供显式 shutdown hook 管理、LIFO 执行顺序和信号绑定。
Example ¶
package main
import (
"context"
"fmt"
"github.com/ZoneCNH/kernel/shutdownx"
)
func main() {
mgr := shutdownx.NewManager()
mgr.Register(shutdownx.HookFunc{
NameValue: "database",
Fn: func(ctx context.Context) error {
fmt.Println("closing database")
return nil
},
})
mgr.Register(shutdownx.HookFunc{
NameValue: "http-server",
Fn: func(ctx context.Context) error {
fmt.Println("stopping http server")
return nil
},
})
err := mgr.Shutdown(context.Background())
fmt.Println("error:", err)
}
Output: stopping http server closing database error: <nil>
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NotifyContext ¶
func NotifyContext(parent context.Context, signals ...os.Signal) (context.Context, context.CancelFunc)
NotifyContext returns a context that is cancelled when any of the specified signals are received. The caller MUST call the returned cancel function to release signal handler resources.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager orchestrates shutdown hooks in LIFO (last-registered, first-executed) order.
func NewManager ¶
NewManager creates a Manager with the given hooks.
Click to show internal directories.
Click to hide internal directories.