]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/aws/aws-sdk-go/private/protocol/restxml/restxml.go
Initial transfer of provider code
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / aws / aws-sdk-go / private / protocol / restxml / restxml.go
1 // Package restxml provides RESTful XML serialization of AWS
2 // requests and responses.
3 package restxml
4
5 //go:generate go run -tags codegen ../../../models/protocol_tests/generate.go ../../../models/protocol_tests/input/rest-xml.json build_test.go
6 //go:generate go run -tags codegen ../../../models/protocol_tests/generate.go ../../../models/protocol_tests/output/rest-xml.json unmarshal_test.go
7
8 import (
9 "bytes"
10 "encoding/xml"
11
12 "github.com/aws/aws-sdk-go/aws/awserr"
13 "github.com/aws/aws-sdk-go/aws/request"
14 "github.com/aws/aws-sdk-go/private/protocol/query"
15 "github.com/aws/aws-sdk-go/private/protocol/rest"
16 "github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil"
17 )
18
19 // BuildHandler is a named request handler for building restxml protocol requests
20 var BuildHandler = request.NamedHandler{Name: "awssdk.restxml.Build", Fn: Build}
21
22 // UnmarshalHandler is a named request handler for unmarshaling restxml protocol requests
23 var UnmarshalHandler = request.NamedHandler{Name: "awssdk.restxml.Unmarshal", Fn: Unmarshal}
24
25 // UnmarshalMetaHandler is a named request handler for unmarshaling restxml protocol request metadata
26 var UnmarshalMetaHandler = request.NamedHandler{Name: "awssdk.restxml.UnmarshalMeta", Fn: UnmarshalMeta}
27
28 // UnmarshalErrorHandler is a named request handler for unmarshaling restxml protocol request errors
29 var UnmarshalErrorHandler = request.NamedHandler{Name: "awssdk.restxml.UnmarshalError", Fn: UnmarshalError}
30
31 // Build builds a request payload for the REST XML protocol.
32 func Build(r *request.Request) {
33 rest.Build(r)
34
35 if t := rest.PayloadType(r.Params); t == "structure" || t == "" {
36 var buf bytes.Buffer
37 err := xmlutil.BuildXML(r.Params, xml.NewEncoder(&buf))
38 if err != nil {
39 r.Error = awserr.New("SerializationError", "failed to encode rest XML request", err)
40 return
41 }
42 r.SetBufferBody(buf.Bytes())
43 }
44 }
45
46 // Unmarshal unmarshals a payload response for the REST XML protocol.
47 func Unmarshal(r *request.Request) {
48 if t := rest.PayloadType(r.Data); t == "structure" || t == "" {
49 defer r.HTTPResponse.Body.Close()
50 decoder := xml.NewDecoder(r.HTTPResponse.Body)
51 err := xmlutil.UnmarshalXML(r.Data, decoder, "")
52 if err != nil {
53 r.Error = awserr.New("SerializationError", "failed to decode REST XML response", err)
54 return
55 }
56 } else {
57 rest.Unmarshal(r)
58 }
59 }
60
61 // UnmarshalMeta unmarshals response headers for the REST XML protocol.
62 func UnmarshalMeta(r *request.Request) {
63 rest.UnmarshalMeta(r)
64 }
65
66 // UnmarshalError unmarshals a response error for the REST XML protocol.
67 func UnmarshalError(r *request.Request) {
68 query.UnmarshalError(r)
69 }