-
Notifications
You must be signed in to change notification settings - Fork 0
/
envelope.go
71 lines (54 loc) · 1.49 KB
/
envelope.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
package financials
import (
"encoding/xml"
"github.com/cydev/zero"
"github.com/omniboost/go-unit4-financials/omitempty"
)
type RequestEnvelope struct {
XMLName xml.Name
NS []xml.Attr `xml:"-"`
Header SOAPHeader `xml:"env:Header,omitempty"`
Body Body `xml:"env:Body"`
}
func NewRequestEnvelope() RequestEnvelope {
return RequestEnvelope{
NS: []xml.Attr{
{Name: xml.Name{Space: "", Local: "xmlns:env"}, Value: "http://schemas.xmlsoap.org/soap/envelope/"},
{Name: xml.Name{Space: "", Local: "xmlns:com"}, Value: "http://www.coda.com/efinance/schemas/common"},
},
Header: NewSOAPHeader(),
}
}
type ResponseEnvelope struct {
XMLName xml.Name
Header SOAPHeader `xml:"Header,omitempty"`
Body Body `xml:"Body"`
}
func (env RequestEnvelope) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
start.Name = xml.Name{Local: "env:Envelope"}
for _, ns := range env.NS {
start.Attr = append(start.Attr, ns)
}
type alias RequestEnvelope
a := alias(env)
return omitempty.MarshalXML(a, e, start)
}
type Body struct {
ActionBody interface{} `xml:",any"`
}
type SOAPHeader struct {
Options Options `xml:"Options"`
}
func (h SOAPHeader) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
return omitempty.MarshalXML(h, e, start)
}
func (h SOAPHeader) IsEmpty() bool {
return zero.IsZero(h)
}
func NewSOAPHeader() SOAPHeader {
return SOAPHeader{}
}
type Options struct {
Locale string `xml:"locale,attr"`
Session string `xml:"session,attr,omitempty"`
}