aboutsummaryrefslogtreecommitdiffstats
path: root/utils/ioutil/common.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2017-02-06 17:55:14 +0100
committerSantiago M. Mola <santi@mola.io>2017-02-06 17:55:14 +0100
commit70eff0d7bd1f69856f8028c2487576085a54a42c (patch)
treee19336caa8b585ce3de467a0d0116383701a8841 /utils/ioutil/common.go
parentc340fb9a0f1f7c025da5ffa2d1a7389a4eabaae2 (diff)
downloadgo-git-70eff0d7bd1f69856f8028c2487576085a54a42c.tar.gz
doc: improve ioutil.CheckClose doc and example, fix #246.
* Use a proper executable example, instead of one in the comment. * Improve wording of CheckClose godoc.
Diffstat (limited to 'utils/ioutil/common.go')
-rw-r--r--utils/ioutil/common.go17
1 files changed, 3 insertions, 14 deletions
diff --git a/utils/ioutil/common.go b/utils/ioutil/common.go
index 12ea9eb..73cc9c3 100644
--- a/utils/ioutil/common.go
+++ b/utils/ioutil/common.go
@@ -64,20 +64,9 @@ func WriteNopCloser(w io.Writer) io.WriteCloser {
return writeNopCloser{w}
}
-// CheckClose is used with defer to close the given io.Closer and check its
-// returned error value. If Close returns an error and the given *error
-// is not nil, *error is set to the error returned by Close.
-//
-// CheckClose is typically used with named return values like so:
-//
-// func do(obj *Object) (err error) {
-// w, err := obj.Writer()
-// if err != nil {
-// return nil
-// }
-// defer CheckClose(w, &err)
-// // work with w
-// }
+// CheckClose calls Close on the given io.Closer. If the given *error points to
+// nil, it will be assigned the error returned by Close. Otherwise, any error
+// returned by Close will be ignored. CheckClose is usually called with defer.
func CheckClose(c io.Closer, err *error) {
if cerr := c.Close(); cerr != nil && *err == nil {
*err = cerr