Help us shape the future of Go! Take the 2026 Go Developer Survey

util

package
v1.21.3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetExitCode

func SetExitCode(err error)

SetExitCode sets the exit code to 1 if the error is not a context.Canceled error.

func SetExitCodeValue added in v1.13.0

func SetExitCodeValue(code int)

SetExitCode sets the exit code to 1 if the error is not a context.Canceled error.

func SetupExitHandler

func SetupExitHandler(parentCtx context.Context, exitBehavior ExitBehavior) (context.Context, func())

SetupExitHandler: A context is returned which is canceled on receiving a shutdown signal (SIGTERM or SIGINT). If a second signal is caught, the program is terminated directly with exit code 130. SetupExitHandler also returns an exit function, this exit function calls os.Exit(...) if there is a exit code in the errorExitCodeChannel. The errorExitCodeChannel receives exit codes when SetExitCode is called or when a shutdown signal is received (only if exitBehavior is AlwaysErrCode).

Types

type ExitBehavior

type ExitBehavior int

ExitBehavior controls how the program should be terminated in response to a shutdown signal.

const (
	// AlwaysErrCode indicates the exit code of the program should always be nonzero
	// and should correspond to the numeric value of the signal that was received.
	AlwaysErrCode ExitBehavior = iota

	// GracefulShutdown treats a shutdown signal as a request to exit gracefully, terminating
	// goroutines and returning an exit code of 0 if there are no errors during shutdown.
	GracefulShutdown ExitBehavior = iota
)

Jump to

Keyboard shortcuts

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