gracefulshutdown

package
v0.0.0-...-b68e1bd Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: Unlicense Imports: 3 Imported by: 0

README

h.go由chatGPT生成,系本人学习使用

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorFunc

type ErrorFunc func(error)

ErrorFunc is a type that wraps a function as an ErrorHandler.

func (ErrorFunc) HandleError

func (ef ErrorFunc) HandleError(err error)

HandleError calls the wrapped function as an ErrorHandler.

type ErrorHandler

type ErrorHandler interface {
	HandleError(error)
}

ErrorHandler is the interface that defines the callback function that will be executed when an error occurs during the shutdown process.

type GSInterface

type GSInterface interface {
	Start(context.Context) error
	AddShutdownManager(ShutdownManager)
	AddShutdownCallback(ShutdownCallback)
	SetErrorHandler(ErrorHandler)
	StartShutdown()
	ReportError(error)
}

GSInterface is the interface that defines the behavior of the GracefulShutdown struct, which is responsible for managing the shutdown process of the application.

type GracefulShutdown

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

GracefulShutdown is a struct that implements the GSInterface.

func NewGracefulShutdown

func NewGracefulShutdown(name string) *GracefulShutdown

NewGracefulShutdown creates a new GracefulShutdown with the given name.

func (*GracefulShutdown) AddShutdownCallback

func (gs *GracefulShutdown) AddShutdownCallback(cb ShutdownCallback)

AddShutdownCallback adds a ShutdownCallback to the GracefulShutdown.

func (*GracefulShutdown) AddShutdownManager

func (gs *GracefulShutdown) AddShutdownManager(sm ShutdownManager)

AddShutdownManager adds a ShutdownManager to the GracefulShutdown.

func (*GracefulShutdown) GetName

func (gs *GracefulShutdown) GetName() string

GetName returns the name of the GracefulShutdown.

func (*GracefulShutdown) ReportError

func (gs *GracefulShutdown) ReportError(err error)

ReportError reports an error to the GracefulShutdown.

func (*GracefulShutdown) SetErrorHandler

func (gs *GracefulShutdown) SetErrorHandler(eh ErrorHandler)

SetErrorHandler sets the ErrorHandler of the GracefulShutdown.

func (*GracefulShutdown) Start

func (gs *GracefulShutdown) Start(ctx context.Context) error

Start starts the GracefulShutdown and returns an error if any.

func (*GracefulShutdown) StartShutdown

func (gs *GracefulShutdown) StartShutdown()

StartShutdown begins the shutdown process of the GracefulShutdown.

type ShutdownCallback

type ShutdownCallback interface {
	Execute() error
}

ShutdownCallback is the interface that defines the callback function that will be executed when the application is shutting down.

type ShutdownFunc

type ShutdownFunc func() error

ShutdownFunc is a type that wraps a function as a ShutdownCallback.

func (ShutdownFunc) Execute

func (sf ShutdownFunc) Execute() error

Execute calls the wrapped function as a ShutdownCallback.

type ShutdownManager

type ShutdownManager interface {
	GetName() string
	Start() error
	BeginShutdown()
	EndShutdown()
}

ShutdownManager is the interface that defines the behavior of a shutdown manager, which is responsible for managing the shutdown process of the application.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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