Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
Refactor PageResult creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
smashwilson committed Jun 24, 2015
1 parent fe80dae commit 2c749a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
10 changes: 8 additions & 2 deletions pagination/http.go
Expand Up @@ -36,13 +36,19 @@ func PageResultFrom(resp *http.Response) (PageResult, error) {
parsedBody = rawBody
}

return PageResultFromParsed(resp, parsedBody), err
}

// PageResultFromParsed constructs a PageResult from an HTTP response that has already had its
// body parsed as JSON (and closed).
func PageResultFromParsed(resp *http.Response, body interface{}) PageResult {
return PageResult{
Result: gophercloud.Result{
Body: parsedBody,
Body: body,
Header: resp.Header,
},
URL: *resp.Request.URL,
}, err
}
}

// Request performs an HTTP request and extracts the http.Response from the result.
Expand Down
9 changes: 1 addition & 8 deletions rackspace/lb/v1/nodes/requests.go
Expand Up @@ -119,14 +119,7 @@ func Create(client *gophercloud.ServiceClient, loadBalancerID int, opts CreateOp
return res
}

pr := pagination.PageResult{
Result: gophercloud.Result{
Body: res.Body,
Header: resp.Header,
},
URL: *resp.Request.URL,
}

pr := pagination.PageResultFromParsed(resp, res.Body)
return CreateResult{pagination.SinglePageBase(pr)}
}

Expand Down

0 comments on commit 2c749a0

Please sign in to comment.