forked from kolo/xmlrpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.go
47 lines (36 loc) · 999 Bytes
/
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
package xmlrpc
import (
"fmt"
"regexp"
)
// responseFailed checks whether response failed or not. Response defined as failed if it
// contains <fault>...</fault> section.
func responseFailed(response []byte) (bool, error) {
fault := true
faultRegexp, err := regexp.Compile(`<fault>(\s|\S)+</fault>`)
if err == nil {
fault = faultRegexp.Match(response)
}
return fault, err
}
func parseSuccessfulResponse(response []byte) (interface{}, error) {
valueXml := getValueXml(response)
return parseValue(valueXml)
}
func parseFailedResponse(response []byte) (err error) {
var valueXml []byte
valueXml = getValueXml(response)
value, err := parseValue(valueXml)
faultDetails := value.(Struct)
if err != nil {
return err
}
return &(xmlrpcError{
code: fmt.Sprintf("%v", faultDetails["faultCode"]),
message: faultDetails["faultString"].(string),
})
}
func getValueXml(rawXml []byte) []byte {
expr, _ := regexp.Compile(`<value>(\s|\S)+</value>`)
return expr.Find(rawXml)
}