generated from alexejk/go-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
decode_response.go
58 lines (48 loc) · 1.77 KB
/
decode_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
56
57
58
package xmlrpc
import "encoding/xml"
// Response is the basic parsed object of the XML-RPC response body.
// While it's not convenient to use this object directly - it contains all the information needed to unmarshal into other data-types.
type Response struct {
Params []*ResponseParam `xml:"params>param"`
Fault *ResponseFault `xml:"fault,omitempty"`
}
// NewResponse creates a Response object from XML body.
// It relies on XML Unmarshaler and if it fails - error is returned.
func NewResponse(body []byte) (*Response, error) {
response := &Response{}
if err := xml.Unmarshal(body, response); err != nil {
return nil, err
}
return response, nil
}
// ResponseParam encapsulates a nested parameter value
type ResponseParam struct {
Value ResponseValue `xml:"value"`
}
// ResponseValue encapsulates one of the data types for each parameter.
// Only one field should be set.
type ResponseValue struct {
Array *ResponseArrayData `xml:"array>data"`
Struct []*ResponseStructMember `xml:"struct>member"`
String *string `xml:"string"`
Int *string `xml:"int"`
Int4 *string `xml:"i4"`
Double *string `xml:"double"`
Boolean *string `xml:"boolean"`
DateTime *string `xml:"dateTime.iso8601"`
Base64 *string `xml:"base64"`
RawXML string `xml:",innerxml"`
}
// ResponseStructMember contains name-value pair of the struct
type ResponseStructMember struct {
Name string `xml:"name"`
Value ResponseValue `xml:"value"`
}
// ResponseArrayData contains a list of array values
type ResponseArrayData struct {
Values []*ResponseValue `xml:"value"`
}
// ResponseFault wraps around failure
type ResponseFault struct {
Value ResponseValue `xml:"value"`
}