shutdown

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 2 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 will be called when shutdown is triggered. The parameter
	// is the name of the shutdown trigger that trigger shutdown.
	OnShutdown(string) error
}

Callback is an interface you have to implement for callbacks.

type CallbackFunc

type CallbackFunc func(string) error

CallbackFunc is a helper type, so you can easily provide anonymous functions as shutdown Callbacks.

func (CallbackFunc) OnShutdown

func (f CallbackFunc) OnShutdown(trigger string) error

type ErrorFunc

type ErrorFunc func(err error)

ErrorFunc is a helper type, so you can easily provide anonymous functions as ErrorHandlers.

func (ErrorFunc) OnError

func (f ErrorFunc) OnError(err error)

OnError defines the action needed to run when error occurred.

type ErrorHandler

type ErrorHandler interface {
	OnError(error)
}

ErrorHandler is an interface you can pass to SetErrorHandler to handle asynchronous errors.

type ExecuteFunc

type ExecuteFunc func(Trigger)

ExecuteFunc defines the execute func.

func (ExecuteFunc) Execute

func (f ExecuteFunc) Execute(trigger Trigger)

type Executor

type Executor interface {
	Execute(Trigger)
}

Executor is the interface of execute func after triggering shutdown.

type Shutdown

type Shutdown interface {
	// Start starts the graceful shutdown controller.
	Start() error
	// AddCallback adds callback func to the shutdown controller.
	AddCallback(Callback)
	// SetErrorHandler set errorHandler for the shutdown controller.
	SetErrorHandler(ErrorHandler)
}

Shutdown is an interface implemented by shutdownController, that receives shutdown triggers when shutdown is requested.

func New

func New(triggers ...Trigger) Shutdown

New returns a new graceful shutdown instance with the specified triggers.

type Trigger

type Trigger interface {
	// GetName returns the name of the trigger.
	GetName() string
	// Start starts the trigger to listen some shutdown requests.
	Start(Executor) error
	// After fun do something after shutdown, like exit.
	After()
}

Trigger is an interface implemnted by shutdown triggers.

Directories

Path Synopsis
trigger

Jump to

Keyboard shortcuts

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