Create a gist now

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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment