Quidest?

Exiting in Go

· Lorenzo Drumond

A Go program automatically exits once it reaches the end of main. If we want to exit before that, we can use the os.Exit function.

We need to pass it a parameter called the exit code, which is just a number. Conventionally, a zero exit status indicates that everything’s fine, while non-zero means some error occurred.

There is also log.Fatal and the panic function to exit early. Both of these will terminate immediatly with non-zero exit status.

References

#package #golang #main #go_tools #code #panic #programming #exit #compiler #compilation #build