This repository has been archived by the owner on Oct 4, 2020. It is now read-only.
/
unmarshal.go
59 lines (49 loc) · 2.01 KB
/
unmarshal.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
package script
import (
"encoding/xml"
"io"
"github.com/aokumasan/nifcloud-sdk-go-v2/private/protocol/xml/xmlutil"
request "github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/awserr"
)
// UnmarshalHandler is a named request handler for unmarshaling script protocol requests
var UnmarshalHandler = request.NamedHandler{Name: "nifcloudsdk.script.Unmarshal", Fn: Unmarshal}
// UnmarshalMetaHandler is a named request handler for unmarshaling script protocol request metadata
var UnmarshalMetaHandler = request.NamedHandler{Name: "nifcloudsdk.script.UnmarshalMeta", Fn: UnmarshalMeta}
// UnmarshalErrorHandler is a named request handler for unmarshaling script protocol request errors
var UnmarshalErrorHandler = request.NamedHandler{Name: "nifcloudsdk.script.UnmarshalError", Fn: UnmarshalError}
// Unmarshal unmarshals a response body for the script protocol.
func Unmarshal(r *request.Request) {
defer r.HTTPResponse.Body.Close()
decoder := xml.NewDecoder(r.HTTPResponse.Body)
err := xmlutil.UnmarshalXML(r.Data, decoder, r.Operation.Name+"Result")
if err != nil {
r.Error = awserr.New("SerializationError", "failed decoding Script response", err)
return
}
}
// UnmarshalMeta unmarshals response headers for the script protocol.
func UnmarshalMeta(r *request.Request) {
// TODO implement unmarshaling of request IDs
}
type xmlErrorResponse struct {
XMLName xml.Name `xml:"ErrorResponse"`
Code string `xml:"Error>Code"`
Message string `xml:"Error>Message"`
RequestID string `xml:"requestId"`
}
// UnmarshalError unmarshals a response error for the script protocol.
func UnmarshalError(r *request.Request) {
defer r.HTTPResponse.Body.Close()
resp := &xmlErrorResponse{}
err := xml.NewDecoder(r.HTTPResponse.Body).Decode(resp)
if err != nil && err != io.EOF {
r.Error = awserr.New("SerializationError", "failed decoding Script error response", err)
} else {
r.Error = awserr.NewRequestFailure(
awserr.New(resp.Code, resp.Message, nil),
r.HTTPResponse.StatusCode,
resp.RequestID,
)
}
}