-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresp_decoder.go
More file actions
32 lines (26 loc) · 905 Bytes
/
resp_decoder.go
File metadata and controls
32 lines (26 loc) · 905 Bytes
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
package greq
import (
"encoding/json"
"encoding/xml"
"net/http"
)
// RespDecoder decodes http responses into struct values.
type RespDecoder interface {
// Decode decodes the response into the value pointed to by ptr.
Decode(resp *http.Response, ptr any) error
}
// jsonDecoder decodes http response JSON into a JSON-tagged struct value.
type jsonDecoder struct {
}
// Decode decodes the Response Body into the value pointed to by ptr.
// Caller must provide a non-nil v and close the resp.Body.
func (d jsonDecoder) Decode(resp *http.Response, ptr any) error {
return json.NewDecoder(resp.Body).Decode(ptr)
}
// XmlDecoder decodes http response body into a XML-tagged struct value.
type XmlDecoder struct {
}
// Decode decodes the Response body into the value pointed to by ptr.
func (d XmlDecoder) Decode(resp *http.Response, ptr any) error {
return xml.NewDecoder(resp.Body).Decode(ptr)
}