forked from hooklift/gowsdl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheader_tmpl.go
77 lines (60 loc) · 1.7 KB
/
header_tmpl.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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package gowsdl
var headerTmpl = `
// Code generated by gowsdl DO NOT EDIT.
package {{.}}
import (
"encoding/xml"
"fmt"
"time"
"github.com/factrylabs/gowsdl/soap"
{{/*range .Imports*/}}
{{/*.*/}}
{{/*end*/}}
)
// against "unused imports"
var _ time.Time
var _ xml.Name
// YB : Added custom timestamp to parse all kinds of different datetime formats
type CustomTimestamp struct {
time.Time
}
// MarshalXML will parse the time.Time back to a string format Navision understands
func (c *CustomTimestamp) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
return e.EncodeElement(c.Time.UTC().Format("2006-01-02T15:04:05Z"), start)
}
// UnmarshalXML will parse the time.Time in different ways - as Navision uses them
func (c *CustomTimestamp) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var v string
d.DecodeElement(&v, &start)
parse, err := time.Parse("2006-01-02T15:04:05Z07:00", v)
if err == nil {
*c = CustomTimestamp{parse}
return nil
}
parse, err = time.Parse("2006-01-02T15:04:05Z", v)
if err == nil {
*c = CustomTimestamp{parse}
return nil
}
parse, err = time.Parse("2006-01-02T15:04:05", v)
if err == nil {
*c = CustomTimestamp{parse}
return nil
}
parse, err = time.Parse("2006-01-02", v)
if err == nil {
*c = CustomTimestamp{parse}
return nil
}
parse, err = time.Parse("15:04:05", v)
if err == nil {
*c = CustomTimestamp{parse}
return nil
}
// if we reach here: an error occurred..
return fmt.Errorf("Could not parse datetime for %v", v)
}
`