os.Exit

The Go function that ends the program immediately with the exit code you give it, such as 0 for success.

In more detail

Deferred functions do not run when you call os.Exit, so call it only from main, after cleanup. Pick codes deliberately and document them: the course uses 0 for success, 1 for a failed check and 2 for a misused command line.

Example

os.Exit(exitBadArgs)

Related terms

Taught in

References