Documentation
¶
Overview ¶
Package shutdown learn from giuhub.com/marmotedu/iam/pkg/shutdown
Index ¶
- type ErrorFunc
- type ErrorHandler
- type GSInterface
- type GracefulShutdown
- func (gs *GracefulShutdown) AddShutdownCallback(shutdownCallback ShutdownCallback)
- func (gs *GracefulShutdown) AddShutdownManager(manager ShutdownManager)
- func (gs *GracefulShutdown) ReportError(err error)
- func (gs *GracefulShutdown) SetErrorHandler(errorHandler ErrorHandler)
- func (gs *GracefulShutdown) Start() error
- func (gs *GracefulShutdown) StartShutdown(sm ShutdownManager)
- type ShutdownCallback
- type ShutdownFunc
- type ShutdownManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrorHandler ¶
type ErrorHandler interface {
OnError(err error)
}
ErrorHandler 接口和 ErrorFunc 类型:用于定义和实现处理异步错误的函数
type GSInterface ¶
type GSInterface interface { StartShutdown(sm ShutdownManager) ReportError(err error) AddShutdownCallback(shutdownCallback ShutdownCallback) }
GSInterface 接口:定义了 GracefulShutdown 结构体的行为,包括启动 ShutdownManager、报告错误、添加 ShutdownCallback 等
type GracefulShutdown ¶
type GracefulShutdown struct {
// contains filtered or unexported fields
}
GracefulShutdown 结构体:实现了上述接口和类型,并提供了 Start、AddShutdownManager、AddShutdownCallback、 SetErrorHandler、StartShutdown、ReportError 等方法, 用于启动和管理 ShutdownManager 和 ShutdownCallbacks
func (*GracefulShutdown) AddShutdownCallback ¶
func (gs *GracefulShutdown) AddShutdownCallback(shutdownCallback ShutdownCallback)
func (*GracefulShutdown) AddShutdownManager ¶
func (gs *GracefulShutdown) AddShutdownManager(manager ShutdownManager)
AddShutdownManager 添加shutdown管理器()
func (*GracefulShutdown) ReportError ¶
func (gs *GracefulShutdown) ReportError(err error)
ReportError是一个可以用来向ErrorHandler报告错误的函数。它在ShutdownManagers中使用。
func (*GracefulShutdown) SetErrorHandler ¶
func (gs *GracefulShutdown) SetErrorHandler(errorHandler ErrorHandler)
func (*GracefulShutdown) Start ¶
func (gs *GracefulShutdown) Start() error
func (*GracefulShutdown) StartShutdown ¶
func (gs *GracefulShutdown) StartShutdown(sm ShutdownManager)
StartShutdown从ShutdownManager调用,将启动shutdown。 首先在Shutdownmanager上调用ShutdownStart, 调用所有的ShutdownCallbacks,等待回调完成, 并在ShutdownManager上调用ShutdownFinish。
type ShutdownCallback ¶
ShutdownCallback 提供了shutdown 前后需要执行的回调函数
type ShutdownFunc ¶
ShutdownFunc是一个helper类型,所以你可以很容易地提供匿名函数ShutdownCallbacks。
func (ShutdownFunc) OnShutdown ¶
func (f ShutdownFunc) OnShutdown(shutdownManager string) error
OnShutdown 定义触发关机时需要运行的操作。
type ShutdownManager ¶
type ShutdownManager interface { GetName() string Start(gs GSInterface) error ShutdownStart() error ShutdownFinish() error }
ShutdownManager 接口:定义了 ShutdownManager 的行为,包括获取名称、启动 ShutdownManager、开始关闭、结束关闭等