exit

package
v0.0.0-...-7cd1858 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error int

Error is an error type that contains a process exit code. This is itended for situations where you want to call os.Exit only in one place, but also want some deeply nested functions to decide what should be the exit code.

func (Error) Code

func (e Error) Code() int

Code returns the exit code.

func (Error) Error

func (e Error) Error() string

Error is the implementation of the error interface.

type Handler

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

Handler knows how to wait for exit signals and how to execute exit actions before exiting.

func (*Handler) AddAction

func (h *Handler) AddAction(value func(ctx context.Context) error)

AddAction adds an action that will be executed prior to exiting.

func (*Handler) AddServer

func (h *Handler) AddServer(value *http.Server)

AddServer adds an HTTP server that should be shutdown prior to exiting.

func (*Handler) Wait

func (h *Handler) Wait(ctx context.Context) error

Wait waits for an exit signal. When it is received it will perform all the registered exit actions and then it will exit the process.

type HandlerBuilder

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

HandlerBuilder contains the data and logic needed to build an exit handler.

func NewHandler

func NewHandler() *HandlerBuilder

NewHandler creates a builder that can then be used to configure and create an exit handler.

func (*HandlerBuilder) AddSignal

func (b *HandlerBuilder) AddSignal(value os.Signal) *HandlerBuilder

AddSignal adds a shutdown signal. Signals SIGINT and SIGTERM are included by default.

func (*HandlerBuilder) AddSignals

func (b *HandlerBuilder) AddSignals(values ...os.Signal) *HandlerBuilder

AddSignals adds a list of exit signal. Signals SIGINT and SIGTERM are included by default.

func (*HandlerBuilder) Build

func (b *HandlerBuilder) Build() (result *Handler, err error)

Build uses the data stored in the builder to create and configure a new exit handler.

func (*HandlerBuilder) SetLogger

func (b *HandlerBuilder) SetLogger(logger *slog.Logger) *HandlerBuilder

SetLogger sets the logger that the handler will use to write to the log. This is mandatory.

func (*HandlerBuilder) SetSignal

func (b *HandlerBuilder) SetSignal(value os.Signal) *HandlerBuilder

SetSignal sets the exit signal, discarding any signals that have been previosly configured, including the defaults.

func (*HandlerBuilder) SetSignals

func (b *HandlerBuilder) SetSignals(values ...os.Signal) *HandlerBuilder

SetSignals sets a list of exit signal, discarding any signals that have been previosly configured, including the defaults.

Jump to

Keyboard shortcuts

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