diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-02-08 11:45:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-08 11:45:07 +0100 |
commit | b65d94e70ea1d013f43234522fa092168e4f1041 (patch) | |
tree | b36da73bd512d1b0ac52e4174ed8b7ed22c75b25 /utils/ioutil/common_test.go | |
parent | 431af32445562b389397f3ee7af90bf61455fff1 (diff) | |
parent | 84b6bd8c22c8683479881a67db03dfdeeeb299ce (diff) | |
download | go-git-b65d94e70ea1d013f43234522fa092168e4f1041.tar.gz |
Merge pull request #259 from smola/docs
Improve documentation
Diffstat (limited to 'utils/ioutil/common_test.go')
-rw-r--r-- | utils/ioutil/common_test.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/utils/ioutil/common_test.go b/utils/ioutil/common_test.go index f5017f7..2d6ef80 100644 --- a/utils/ioutil/common_test.go +++ b/utils/ioutil/common_test.go @@ -3,6 +3,7 @@ package ioutil import ( "bytes" "io/ioutil" + "strings" "testing" . "gopkg.in/check.v1" @@ -53,3 +54,25 @@ func (s *CommonSuite) TestNewReadCloser(c *C) { c.Assert(r.Close(), IsNil) c.Assert(closer.called, Equals, 1) } + +func ExampleCheckClose() { + // CheckClose is commonly used with named return values + f := func() (err error) { + // Get a io.ReadCloser + r := ioutil.NopCloser(strings.NewReader("foo")) + + // defer CheckClose call with an io.Closer and pointer to error + defer CheckClose(r, &err) + + // ... work with r ... + + // if err is not nil, CheckClose will assign any close errors to it + return err + + } + + err := f() + if err != nil { + panic(err) + } +} |