process

package
v0.10.0 Latest Latest
Warning

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

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

Documentation

Overview

Package process holds the parts of a binary's main sequence that run before the program's own infrastructure exists: reporting a failure or a usage error when there is no logger yet, the signal-derived root context, and the exit-code convention the reporters return. An application's entrypoint, the minimal binary above its composition root, composes its run function from it, so the convention cannot drift between a program's binaries.

The package exports:

  • ExitOK, ExitFailure, and ExitUsage, the exit codes
  • Fail, which reports a runtime failure and returns ExitFailure
  • Usage, which reports a usage error or help and returns ExitUsage
  • SignalContext, which returns the root context SIGINT or SIGTERM cancels

Index

Constants

View Source
const (
	ExitOK      = 0
	ExitFailure = 1
	ExitUsage   = 2
)

Exit codes shared by a program's binaries: 0 ok, 1 runtime failure, 2 usage error.

Variables

This section is empty.

Functions

func Fail

func Fail(w io.Writer, msg string, err error) int

Fail writes "msg: err" to w and returns ExitFailure.

func SignalContext

func SignalContext() (context.Context, context.CancelFunc)

SignalContext returns a context cancelled on SIGINT or SIGTERM, and the stop function that releases the signal registration. Call stop once the context is done, so a second signal terminates the process at once.

func Usage

func Usage(w io.Writer, text string) int

Usage writes text as a line to w and returns ExitUsage. Requested help goes through it too.

Types

This section is empty.

Directories

Path Synopsis
Package processtest is the integration toolkit for a program built on the process package.
Package processtest is the integration toolkit for a program built on the process package.
internal/testprog command
Command testprog is the program the processtest package's own tests run: it answers on a loopback address, waits for the interrupt, and exits with the code its environment names, so the runner is proved against a real subprocess without a service behind it.
Command testprog is the program the processtest package's own tests run: it answers on a loopback address, waits for the interrupt, and exits with the code its environment names, so the runner is proved against a real subprocess without a service behind it.

Jump to

Keyboard shortcuts

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