/
eet-gen.go
274 lines (238 loc) · 7.7 KB
/
eet-gen.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
// Code generated by wsdlgen. DO NOT EDIT.
// Package eet
//
package eet
import (
"bytes"
"context"
"encoding/base64"
"encoding/xml"
"fmt"
"io"
"net/http"
"time"
)
// May be one of SHA1
type BkpDigestType string
type BkpElementType struct {
BkpType BkpType `xml:",chardata"`
Digest BkpDigestType `xml:"digest,attr"`
Encoding BkpEncodingType `xml:"encoding,attr"`
}
// May be one of base16
type BkpEncodingType string
// Must match the pattern [0-9a-fA-F]{8}-[0-9a-fA-F]{8}-[0-9a-fA-F]{8}-[0-9a-fA-F]{8}-[0-9a-fA-F]{8}
type BkpType string
// Must match the pattern CZ[0-9]{8,10}
type CZDICType string
// Must match the pattern ((0|-?[1-9]\d{0,7})\.\d\d|-0\.(0[1-9]|[1-9]\d))
type CastkaType float64
type DateTime time.Time
func (t *DateTime) UnmarshalText(text []byte) error {
return (*xsdDateTime)(t).UnmarshalText(text)
}
func (t DateTime) MarshalText() ([]byte, error) {
return xsdDateTime(t).MarshalText()
}
// Must match the pattern [0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}-[0-9a-fA-F]{2}
type FikType string
type OdpovedChybaType struct {
Zprava string `xml:",chardata"`
Kod int `xml:"kod,attr"`
Test bool `xml:"test,attr,omitempty"`
}
type OdpovedHlavickaType struct {
Uuidzpravy UUIDType `xml:"uuid_zpravy,attr,omitempty"`
Bkp BkpType `xml:"bkp,attr,omitempty"`
Datprij DateTime `xml:"dat_prij,attr,omitempty"`
Datodmit DateTime `xml:"dat_odmit,attr,omitempty"`
}
type OdpovedPotvrzeniType struct {
Fik FikType `xml:"fik,attr"`
Test bool `xml:"test,attr,omitempty"`
}
type OdpovedType struct {
Hlavicka OdpovedHlavickaType `xml:"Hlavicka,omitempty"`
Potvrzeni OdpovedPotvrzeniType `xml:"Potvrzeni,omitempty"`
Chyba OdpovedChybaType `xml:"Chyba,omitempty"`
Varovani []OdpovedVarovaniType `xml:"Varovani,omitempty"`
}
type OdpovedVarovaniType struct {
Zprava string `xml:",chardata"`
Kodvarov int `xml:"kod_varov,attr"`
}
// May be one of RSA2048
type PkpCipherType string
// May be one of SHA256
type PkpDigestType string
type PkpElementType struct {
PkpType PkpType `xml:",chardata"`
Digest PkpDigestType `xml:"digest,attr"`
Cipher PkpCipherType `xml:"cipher,attr"`
Encoding PkpEncodingType `xml:"encoding,attr"`
}
// May be one of base64
type PkpEncodingType string
type PkpType []byte
func (t *PkpType) UnmarshalText(text []byte) error {
return (*xsdBase64Binary)(t).UnmarshalText(text)
}
func (t PkpType) MarshalText() ([]byte, error) {
return xsdBase64Binary(t).MarshalText()
}
// May be one of 0, 1
type RezimType int
// Must match the pattern [0-9a-zA-Z\.,:;/#\-_ ]{1,20}
type String20 string
// Must match the pattern [0-9a-zA-Z\.,:;/#\-_ ]{1,25}
type String25 string
type TrzbaDataType struct {
Dicpopl CZDICType `xml:"dic_popl,attr"`
Dicpoverujiciho CZDICType `xml:"dic_poverujiciho,attr,omitempty"`
Idprovoz int `xml:"id_provoz,attr"`
Idpokl String20 `xml:"id_pokl,attr"`
Poradcis String25 `xml:"porad_cis,attr"`
Dattrzby DateTime `xml:"dat_trzby,attr"`
Celktrzba CastkaType `xml:"celk_trzba,attr"`
Zaklnepodldph CastkaType `xml:"zakl_nepodl_dph,attr,omitempty"`
Zakldan1 CastkaType `xml:"zakl_dan1,attr,omitempty"`
Dan1 CastkaType `xml:"dan1,attr,omitempty"`
Zakldan2 CastkaType `xml:"zakl_dan2,attr,omitempty"`
Dan2 CastkaType `xml:"dan2,attr,omitempty"`
Zakldan3 CastkaType `xml:"zakl_dan3,attr,omitempty"`
Dan3 CastkaType `xml:"dan3,attr,omitempty"`
Cestsluz CastkaType `xml:"cest_sluz,attr,omitempty"`
Pouzitzboz1 CastkaType `xml:"pouzit_zboz1,attr,omitempty"`
Pouzitzboz2 CastkaType `xml:"pouzit_zboz2,attr,omitempty"`
Pouzitzboz3 CastkaType `xml:"pouzit_zboz3,attr,omitempty"`
Urcenocerpzuct CastkaType `xml:"urceno_cerp_zuct,attr,omitempty"`
Cerpzuct CastkaType `xml:"cerp_zuct,attr,omitempty"`
Rezim RezimType `xml:"rezim,attr"`
}
type TrzbaHlavickaType struct {
Uuidzpravy UUIDType `xml:"uuid_zpravy,attr"`
Datodesl DateTime `xml:"dat_odesl,attr"`
Prvnizaslani bool `xml:"prvni_zaslani,attr"`
Overeni bool `xml:"overeni,attr,omitempty"`
}
type TrzbaKontrolniKodyType struct {
Pkp PkpElementType `xml:"pkp"`
Bkp BkpElementType `xml:"bkp"`
}
type TrzbaType struct {
Hlavicka TrzbaHlavickaType `xml:"Hlavicka"`
Data TrzbaDataType `xml:"Data"`
KontrolniKody TrzbaKontrolniKodyType `xml:"KontrolniKody"`
}
// Must match the pattern [0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}
type UUIDType string
type xsdBase64Binary []byte
func (b *xsdBase64Binary) UnmarshalText(text []byte) (err error) {
*b, err = base64.StdEncoding.DecodeString(string(text))
return
}
func (b xsdBase64Binary) MarshalText() ([]byte, error) {
var buf bytes.Buffer
enc := base64.NewEncoder(base64.StdEncoding, &buf)
enc.Write([]byte(b))
enc.Close()
return buf.Bytes(), nil
}
type xsdDateTime time.Time
func (t *xsdDateTime) UnmarshalText(text []byte) error {
return _unmarshalTime(text, (*time.Time)(t), "2006-01-02T15:04:05.999999999")
}
func (t xsdDateTime) MarshalText() ([]byte, error) {
return _marshalTime((time.Time)(t), "2006-01-02T15:04:05.999999999")
}
func (t xsdDateTime) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
if (time.Time)(t).IsZero() {
return nil
}
m, err := t.MarshalText()
if err != nil {
return err
}
return e.EncodeElement(m, start)
}
func (t xsdDateTime) MarshalXMLAttr(name xml.Name) (xml.Attr, error) {
if (time.Time)(t).IsZero() {
return xml.Attr{}, nil
}
m, err := t.MarshalText()
return xml.Attr{Name: name, Value: string(m)}, err
}
func _unmarshalTime(text []byte, t *time.Time, format string) (err error) {
s := string(bytes.TrimSpace(text))
*t, err = time.Parse(format, s)
if _, ok := err.(*time.ParseError); ok {
*t, err = time.Parse(format+"Z07:00", s)
}
return err
}
func _marshalTime(t time.Time, format string) ([]byte, error) {
return []byte(t.Format(format + "Z07:00")), nil
}
type Client struct {
HTTPClient *http.Client
ResponseHook func(*http.Response) *http.Response
RequestHook func(*http.Request) *http.Request
}
type soapEnvelope struct {
XMLName struct{} `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
Header []byte `xml:"http://schemas.xmlsoap.org/soap/envelope/ Header"`
Body struct {
Message interface{}
Fault *struct {
String string `xml:"faultstring,omitempty"`
Code string `xml:"faultcode,omitempty"`
Detail string `xml:"detail,omitempty"`
} `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
} `xml:"http://schemas.xmlsoap.org/soap/envelope/ Body"`
}
func (c *Client) do(ctx context.Context, method, uri, action string, in, out interface{}) error {
var body io.Reader
var envelope soapEnvelope
if method == "POST" || method == "PUT" {
var buf bytes.Buffer
envelope.Body.Message = in
enc := xml.NewEncoder(&buf)
if err := enc.Encode(envelope); err != nil {
return err
}
if err := enc.Flush(); err != nil {
return err
}
body = &buf
}
req, err := http.NewRequest(method, uri, body)
if err != nil {
return err
}
req.Header.Set("SOAPAction", action)
req = req.WithContext(ctx)
if c.RequestHook != nil {
req = c.RequestHook(req)
}
httpClient := c.HTTPClient
if httpClient == nil {
httpClient = http.DefaultClient
}
rsp, err := httpClient.Do(req)
if err != nil {
return err
}
defer rsp.Body.Close()
if c.ResponseHook != nil {
rsp = c.ResponseHook(rsp)
}
dec := xml.NewDecoder(rsp.Body)
envelope.Body.Message = out
if err := dec.Decode(&envelope); err != nil {
return err
}
if envelope.Body.Fault != nil {
return fmt.Errorf("%s: %s", envelope.Body.Fault.Code, envelope.Body.Fault.String)
}
return nil
}