forked from vickxxx/appstore
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathresource.go
35 lines (30 loc) · 1.01 KB
/
resource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package appstore
import (
"fmt"
"net/http"
)
//ResourceAbstract base resource
type ResourceAbstract struct {
transport *Transport
config *Config
}
//UnmarshalResponse method
func (ra *ResourceAbstract) unmarshalResponse(resp *http.Response, v interface{}, filterLines bool) error {
contentType := resp.Header.Get("Content-Type")
responseHandler := NewResponseHandler(contentType, filterLines)
bodyBytes, err := responseHandler.ReadBody(resp)
if err != nil {
return fmt.Errorf("ResourceAbstract.unmarshalResponse read body: %v", err)
}
//reset the response body to the original unread state
body, err := responseHandler.RestoreBody(bodyBytes)
if err != nil {
return fmt.Errorf("ResourceAbstract.unmarshalResponse read body: %v", err)
}
resp.Body = body
return responseHandler.UnmarshalBody(bodyBytes, v)
}
//newResourceAbstract create new resource abstract
func newResourceAbstract(transport *Transport, config *Config) ResourceAbstract {
return ResourceAbstract{transport: transport, config: config}
}