Skip to content

Instantly share code, notes, and snippets.

@petergtz
Created June 19, 2017 10:00
Show Gist options
  • Save petergtz/b4d32b1c3d767e624aa0a57c57e783c5 to your computer and use it in GitHub Desktop.
Save petergtz/b4d32b1c3d767e624aa0a57c57e783c5 to your computer and use it in GitHub Desktop.
a little helper for correct error handling in Go
type SafeCloser bool
func (safeCloser *SafeCloser) Close(closer io.Closer) error {
if *safeCloser {
return nil
}
*safeCloser = true
return closer.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment