Created
June 19, 2017 10:00
-
-
Save petergtz/b4d32b1c3d767e624aa0a57c57e783c5 to your computer and use it in GitHub Desktop.
a little helper for correct error handling in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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