Skip to content

Instantly share code, notes, and snippets.


benbjohnson/close.go Secret

Created Jun 12, 2017
What would you like to do?
func doSomething() error {
f, err := os.Create("foo")
if err != nil {
return err
defer f.Close()
if _, err := f.Write([]byte("bar"); err != nil {
return err
if err := f.Close(); err != nil {
return err
return nil

This comment has been minimized.

Copy link

@abonec abonec commented Jan 18, 2019

Why not just return f.Close() instead of if statement?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment