~ubuntu-branches/debian/stretch/golang-github-aws-aws-sdk-go/stretch

« back to all changes in this revision

Viewing changes to internal/protocol/ec2query/unmarshal.go

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2015-09-29 12:34:07 UTC
  • Revision ID: package-import@ubuntu.com-20150929123407-7xmll3gdhvb9zh2l
Tags: upstream-0.9.9+dfsg
ImportĀ upstreamĀ versionĀ 0.9.9+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package ec2query
 
2
 
 
3
//go:generate go run ../../fixtures/protocol/generate.go ../../fixtures/protocol/output/ec2.json unmarshal_test.go
 
4
 
 
5
import (
 
6
        "encoding/xml"
 
7
        "io"
 
8
 
 
9
        "github.com/aws/aws-sdk-go/aws/awserr"
 
10
        "github.com/aws/aws-sdk-go/aws/request"
 
11
        "github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil"
 
12
)
 
13
 
 
14
// Unmarshal unmarshals a response body for the EC2 protocol.
 
15
func Unmarshal(r *request.Request) {
 
16
        defer r.HTTPResponse.Body.Close()
 
17
        if r.DataFilled() {
 
18
                decoder := xml.NewDecoder(r.HTTPResponse.Body)
 
19
                err := xmlutil.UnmarshalXML(r.Data, decoder, "")
 
20
                if err != nil {
 
21
                        r.Error = awserr.New("SerializationError", "failed decoding EC2 Query response", err)
 
22
                        return
 
23
                }
 
24
        }
 
25
}
 
26
 
 
27
// UnmarshalMeta unmarshals response headers for the EC2 protocol.
 
28
func UnmarshalMeta(r *request.Request) {
 
29
        // TODO implement unmarshaling of request IDs
 
30
}
 
31
 
 
32
type xmlErrorResponse struct {
 
33
        XMLName   xml.Name `xml:"Response"`
 
34
        Code      string   `xml:"Errors>Error>Code"`
 
35
        Message   string   `xml:"Errors>Error>Message"`
 
36
        RequestID string   `xml:"RequestId"`
 
37
}
 
38
 
 
39
// UnmarshalError unmarshals a response error for the EC2 protocol.
 
40
func UnmarshalError(r *request.Request) {
 
41
        defer r.HTTPResponse.Body.Close()
 
42
 
 
43
        resp := &xmlErrorResponse{}
 
44
        err := xml.NewDecoder(r.HTTPResponse.Body).Decode(resp)
 
45
        if err != nil && err != io.EOF {
 
46
                r.Error = awserr.New("SerializationError", "failed decoding EC2 Query error response", err)
 
47
        } else {
 
48
                r.Error = awserr.NewRequestFailure(
 
49
                        awserr.New(resp.Code, resp.Message, nil),
 
50
                        r.HTTPResponse.StatusCode,
 
51
                        resp.RequestID,
 
52
                )
 
53
        }
 
54
}