What\'s the idiomatic way to exit a program with some error code?
The documentation for Exit
says \"The program terminates immediately; deferred functions a
I do something along these lines in most of my real main
packages, so that the return err
convention is adopted as soon as possible, and has a proper termination:
func main() {
if err := run(); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}
func run() error {
err := something()
if err != nil {
return err
}
// etc
}