Skip to content

Instantly share code, notes, and snippets.

@wheaties
Created October 17, 2014 15:59
Show Gist options
  • Save wheaties/5cd55e26d5600b789b39 to your computer and use it in GitHub Desktop.
Save wheaties/5cd55e26d5600b789b39 to your computer and use it in GitHub Desktop.
Capture defer error
type Capture struct{
closer *Closer
err error
}
func (cap Capture) Close() error {
cap.err = cap.closer.Close()
return cap.err
}
func DoSomething(cl *ReadCloser) (thing, error) {
var cap = Capture{cl, nil}
defer cap.Close()
out, err := GetThing(cl, "something")
if err != nil {
return nil, err
}
return out, cap.err
}
@wheaties
Copy link
Author

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