MCPcopy Create free account
hub / github.com/go-git/go-git / ExampleCheckClose

Function ExampleCheckClose

utils/ioutil/common_test.go:159–178  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

157 c.Assert(called, NotNil)
158}
159func ExampleCheckClose() {
160 // CheckClose is commonly used with named return values
161 f := func() (err error) {
162 // Get a io.ReadCloser
163 r := io.NopCloser(strings.NewReader("foo"))
164
165 // defer CheckClose call with an io.Closer and pointer to error
166 defer CheckClose(r, &err)
167
168 // ... work with r ...
169
170 // if err is not nil, CheckClose will assign any close errors to it
171 return err
172 }
173
174 err := f()
175 if err != nil {
176 panic(err)
177 }
178}

Callers

nothing calls this directly

Calls 1

CheckCloseFunction · 0.85

Tested by

no test coverage detected