Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be caseful with os.Exit #3

Open
shaardie opened this issue Apr 26, 2019 · 0 comments
Open

Be caseful with os.Exit #3

shaardie opened this issue Apr 26, 2019 · 0 comments

Comments

@shaardie
Copy link

Unfortunately os.Exit simply exits the program where it is called. So it stops every kind of reasonable teardown. So think about only using it on the main of your program to make sure everything shuts down correctly.

Funnily enough, most of my golang programs ends with a structure like this

package main

import (
	"os"
)

func mainWithError() error {
	// Here should be program...
	return nil
}

func main() {
	err := mainWithError()
	if err != nil {
		os.Exit(1)
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant