mirror of
https://github.com/rclone/rclone.git
synced 2026-01-07 19:13:19 +00:00
Make fs.CheckClose public to stop duplication
This commit is contained in:
13
rest/rest.go
13
rest/rest.go
@@ -29,7 +29,7 @@ func NewClient(c *http.Client, rootURL string) *Client {
|
||||
|
||||
// defaultErrorHandler doesn't attempt to parse the http body
|
||||
func defaultErrorHandler(resp *http.Response) (err error) {
|
||||
defer checkClose(resp.Body, &err)
|
||||
defer fs.CheckClose(resp.Body, &err)
|
||||
return fmt.Errorf("HTTP error %v (%v) returned", resp.StatusCode, resp.Status)
|
||||
}
|
||||
|
||||
@@ -52,18 +52,9 @@ type Opts struct {
|
||||
ExtraHeaders map[string]string
|
||||
}
|
||||
|
||||
// checkClose is a utility function used to check the return from
|
||||
// Close in a defer statement.
|
||||
func checkClose(c io.Closer, err *error) {
|
||||
cerr := c.Close()
|
||||
if *err == nil {
|
||||
*err = cerr
|
||||
}
|
||||
}
|
||||
|
||||
// DecodeJSON decodes resp.Body into result
|
||||
func DecodeJSON(resp *http.Response, result interface{}) (err error) {
|
||||
defer checkClose(resp.Body, &err)
|
||||
defer fs.CheckClose(resp.Body, &err)
|
||||
decoder := json.NewDecoder(resp.Body)
|
||||
return decoder.Decode(result)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user