-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse.go
55 lines (45 loc) · 1.04 KB
/
response.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package okhttp
import (
"encoding/json"
"net/http"
)
// Response r
type Response struct {
request *Request
headers http.Header
cookies []*http.Cookie
status int
body []byte
}
// GetCookies returns response cookies slice
func (r *Response) GetCookies() []*http.Cookie {
return r.cookies
}
// GetBody returns response body
func (r *Response) GetBody() []byte {
return r.body
}
// String returns response body as string
func (r *Response) String() string {
return string(r.GetBody())
}
// GetJSON unmarshal JSON response to struct
func (r *Response) GetJSON(v interface{}) error {
return json.Unmarshal(r.body, v)
}
// GetHeaders return response headers
func (r *Response) GetHeaders() H {
return doHeader(r.headers)
}
// GetRequest returns initial request
func (r *Response) GetRequest() *Request {
return r.request
}
// GetStatus returns response status code
func (r *Response) GetStatus() int {
return r.status
}
// GetHeader returns response header by name
func (r *Response) GetHeader(key string) string {
return r.headers.Get(key)
}