-
Notifications
You must be signed in to change notification settings - Fork 2
/
decode.go
125 lines (110 loc) · 2.97 KB
/
decode.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Package soap implements SOAP-logic for the TransIP API.
// decode.go contains the logic to convert the XML to the corresponding
// datastructures
package transip
import (
"bytes"
"encoding/xml"
"errors"
"io"
)
type SOAPFault struct {
XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault"`
Code string `xml:"faultcode,omitempty"`
String string `xml:"faultstring,omitempty"`
Actor string `xml:"faultactor,omitempty"`
Detail string `xml:"detail,omitempty"`
}
type domainNames struct {
Item []string `xml:"item"`
}
type availability struct {
Item string `xml:"return"`
}
type Domains struct {
Domains []Domain `xml:"item"`
}
type DomainNameserver struct {
Hostname string `xml:"hostname"`
IPv4 string `xml:"ipv4"`
IPv6 string `xml:"ipv6"`
}
type DomainContact struct {
Type string `xml:"type"`
FirstName string `xml:"firstName"`
MiddleName string `xml:"middleName"`
LastName string `xml:"lastName"`
CompanyName string `xml:"companyName"`
CompanyKvK string `xml:"companyKvk"`
CompanyType string `xml:"companyType"`
Street string `xml:"street"`
Number string `xml:"number"`
PostalCode string `xml:"postalCode"`
City string `xml:"city"`
PhoneNumber string `xml:"phoneNumber"`
FaxNumber string `xml:"faxNumber"`
Email string `xml:"email"`
Country string `xml:"country"`
}
type DomainDNSentry struct {
Name string `xml:"name"`
Expire int `xml:"expire"`
Type string `xml:"type"`
Content string `xml:"content"`
}
type Domain struct {
Name string `xml:"name"`
Nameservers []DomainNameserver `xml:"nameservers>item"`
Contacts []DomainContact `xml:"contacts>item"`
DNSEntry []DomainDNSentry `xml:"dnsEntries>item"`
AuthCode string `xml:"authCode"`
IsLocked bool `xml:"isLocked"`
RegistrationDate string `xml:"registrationDate"`
RenewalDate string `xml:"renewalDate"`
}
type domainCheckResults struct {
Results []DomainCheckResult `xml:"item"`
}
type DomainCheckResult struct {
DomainName string `xml:"domainName"`
Status string `xml:"status"`
Actions []string `xml:"actions>item"`
}
// Convert rawbody to XML and subtract the 'body' from the
// SOAP-envelope into the struct given with out
func decode(rawbody []byte, out interface{}) error {
dec := xml.NewDecoder(bytes.NewReader(rawbody))
for {
tok, e := dec.Token()
if e == io.EOF {
return nil
}
if e != nil {
return e
}
switch se := tok.(type) {
case xml.StartElement:
if se.Name.Local == "checkAvailabilityResponse" {
// Start readin'!
if e := dec.DecodeElement(out, &se); e != nil {
return e
}
}
if se.Name.Local == "return" {
// Start readin'!
if e := dec.DecodeElement(out, &se); e != nil {
return e
}
}
if se.Name.Local == "Fault" {
// Error!
err := &SOAPFault{}
if e := dec.DecodeElement(err, &se); e != nil {
return e
}
return errors.New("soapFault: " + err.String)
}
}
}
return nil
}