1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-09-12 05:06:28 +00:00
arikawa/utils/httputil/driverwrap.go
2021-06-01 19:59:01 -07:00

43 lines
804 B
Go

package httputil
import (
"io"
"github.com/diamondburned/arikawa/v3/utils/httputil/httpdriver"
)
// This file contains mistakes.
// httpResponse wraps around a httpdriver.Response to provide a custom body.
type httpResponse struct {
httpdriver.Response
body io.ReadCloser
}
func wrapCancelableResponse(r httpdriver.Response, cancel func()) httpdriver.Response {
body := bodyCloser{
ReadCloser: r.GetBody(),
close: cancel,
}
return httpResponse{
Response: r,
body: body,
}
}
func (resp httpResponse) GetBody() io.ReadCloser {
return resp.body
}
// bodyCloser wraps around a body to add an additional close callback.
type bodyCloser struct {
io.ReadCloser
close func()
}
func (body bodyCloser) Close() error {
err := body.ReadCloser.Close()
body.close()
return err
}