shutdown

package
v0.0.0-...-4f9d474 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback interface {
	OnShutdown(manager string) error
}

type CallbackFunc

type CallbackFunc func(string) error

CallbackFunc 是一个辅助函数,用于自定义回调函数.

func (CallbackFunc) OnShutdown

func (f CallbackFunc) OnShutdown(manager string) error

OnShutdown 是在 shutdown 触发时执行的方法.

type ErrorHandler

type ErrorHandler interface {
	OnError(err error)
}

type GSInterface

type GSInterface interface {
	AddManager(manager Manager)                // 添加 Shutdown Manager
	AddCallback(callback Callback)             // 添加 Shutdown Callback
	SetErrorHandler(errorHandler ErrorHandler) // 设置 ErrorHandler

	StartShutdown(manager Manager) // 执行指定 Manager 的 shutdown
	ReportError(err error)         // 向 ErrorHandler 报错
}

type GracefulShutdown

type GracefulShutdown struct {
	// contains filtered or unexported fields
}

func New

func New() *GracefulShutdown

New 初始化优雅关闭实例.

func (*GracefulShutdown) AddCallback

func (gs *GracefulShutdown) AddCallback(callback Callback)

AddCallback 添加 Callback 以便在 shutdown 时调用.

func (*GracefulShutdown) AddManager

func (gs *GracefulShutdown) AddManager(manager Manager)

AddManager 添加 Manager 用于监听 shutdown 请求.

func (*GracefulShutdown) ReportError

func (gs *GracefulShutdown) ReportError(err error)

ReportError 用于向 ErrorHandler 报错.

func (*GracefulShutdown) SetErrorHandler

func (gs *GracefulShutdown) SetErrorHandler(errorHandler ErrorHandler)

SetErrorHandler 设置 ErrorHandler 用于在 Manager 或 Callback 失败时调用.

func (*GracefulShutdown) Start

func (gs *GracefulShutdown) Start() error

Start 在所有已添加的 Manager 上启动监听.

func (*GracefulShutdown) StartShutdown

func (gs *GracefulShutdown) StartShutdown(manager Manager)

StartShutdown 用于执行指定 Manager 的 shutdown.

type Manager

type Manager interface {
	GetName() string
	Start(gs GSInterface) error
	ShutdownStart() error
	ShutdownFinish() error
}

Directories

Path Synopsis
managers

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL