-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.go
86 lines (73 loc) · 2.02 KB
/
tools.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
package soap
import (
"encoding/xml"
"fmt"
"github.com/fiorix/wsdl2go/soap"
)
// IntPtr is a wrapper to create inline pointer to int
func IntPtr(n int) *int {
return &n
}
// StringPtr is a wrapper to create inline pointer to string
func StringPtr(s string) *string {
return &s
}
// ArrToAOS is a wrapper to create inline pointer to Array of String
func ArrToAOS(arr []string) *ArrayOfString {
arrToPTR := make([]*string, 0, len(arr))
for k := range arr {
arrToPTR = append(arrToPTR, &arr[k])
}
return &ArrayOfString{
String: arrToPTR,
}
}
// ArrToAOI is a wrapper to create inline pointer to Array of Int
func ArrToAOI(arr []int) *ArrayOfInt {
arrToPTR := make([]*int, 0, len(arr))
for k := range arr {
arrToPTR = append(arrToPTR, &arr[k])
}
return &ArrayOfInt{
Integer: arrToPTR,
}
}
// SoapError used for unmarshaling Service Desk SOAP API errors
type SoapError struct {
XMLName xml.Name `xml:"Envelope"`
FaultCode string `xml:"Body>Fault>faultcode"`
FaultString string `xml:"Body>Fault>faultstring"`
FaultActor string `xml:"Body>Fault>faultactor"`
ErrorCode int `xml:"Body>Fault>detail>ErrorCode"`
ErrorMsg string `xml:"Body>Fault>detail>ErrorMessage"`
}
func (e *SoapError) Error() string {
return fmt.Sprintf("%d: %s", e.ErrorCode, e.ErrorMsg)
}
func ParseSoapError(err error) *SoapError {
switch terr := err.(type) {
case *soap.HTTPError:
var soapErr SoapError
err := xml.Unmarshal([]byte(terr.Msg), &soapErr)
if err == nil {
return &soapErr
}
}
return nil
}
// USDObjectList is for
type USDObjectList struct {
XMLName xml.Name `xml:"UDSObjectList" json:"xml_name"`
UDSObject []USDObject `xml:"UDSObject" json:"uds_object"`
}
// USDObject is for
type USDObject struct {
Handle string `xml:"Handle" json:"persistent_id"`
Attributes []USDObjectAttrs `xml:"Attributes>Attribute" json:"attr"`
}
// USDObjectAttrs is for
type USDObjectAttrs struct {
AttrName string `xml:"AttrName" json:"a"`
AttrValue string `xml:"AttrValue" json:"v"`
}
func UmarshalError() {}