github.com/diamondburned/arikawa/v2@v2.1.0/utils/httputil/driverwrap.go (about) 1 package httputil 2 3 import ( 4 "io" 5 6 "github.com/diamondburned/arikawa/v2/utils/httputil/httpdriver" 7 ) 8 9 // This file contains mistakes. 10 11 // httpResponse wraps around a httpdriver.Response to provide a custom body. 12 type httpResponse struct { 13 httpdriver.Response 14 body io.ReadCloser 15 } 16 17 func wrapCancelableResponse(r httpdriver.Response, cancel func()) httpdriver.Response { 18 body := bodyCloser{ 19 ReadCloser: r.GetBody(), 20 close: cancel, 21 } 22 return httpResponse{ 23 Response: r, 24 body: body, 25 } 26 } 27 28 func (resp httpResponse) GetBody() io.ReadCloser { 29 return resp.body 30 } 31 32 // bodyCloser wraps around a body to add an additional close callback. 33 type bodyCloser struct { 34 io.ReadCloser 35 close func() 36 } 37 38 func (body bodyCloser) Close() error { 39 err := body.ReadCloser.Close() 40 body.close() 41 return err 42 }