-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.go
58 lines (50 loc) · 1.14 KB
/
parse.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 main
import (
"encoding/xml"
"io"
"strings"
)
func parse(body io.Reader) (error, error) {
dec := xml.NewDecoder(body)
dec.CharsetReader = func(charset string, r io.Reader) (io.Reader, error) {
return r, nil
}
var result apiResponse
if err := dec.Decode(&result); err != nil {
return nil, err
}
if result.ErrCount > 0 {
return result, nil
}
return nil, nil
}
type apiResponse struct {
ErrCount int `xml:"ErrCount"`
Errors struct {
Err1 string `xml:"Err1,omitempty"`
Err2 string `xml:"Err2,omitempty"`
Err3 string `xml:"Err3,omitempty"`
Err4 string `xml:"Err4,omitempty"`
Err5 string `xml:"Err5,omitempty"`
Err6 string `xml:"Err6,omitempty"`
Err7 string `xml:"Err7,omitempty"`
Err8 string `xml:"Err8,omitempty"`
Err9 string `xml:"Err9,omitempty"`
Err10 string `xml:"Err10,omitempty"`
} `xml:"errors"`
}
var _ error = apiResponse{}
func (r apiResponse) Error() string {
return strings.Join([]string{
r.Errors.Err1,
r.Errors.Err2,
r.Errors.Err3,
r.Errors.Err4,
r.Errors.Err5,
r.Errors.Err6,
r.Errors.Err7,
r.Errors.Err8,
r.Errors.Err9,
r.Errors.Err10,
}[:r.ErrCount], " & ")
}