Skip to content

Instantly share code, notes, and snippets.

@benbjohnson benbjohnson/close.go Secret
Created Jun 12, 2017

Embed
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
}
@abonec

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.