1
0
Fork 0
mirror of https://github.com/Luzifer/mondash.git synced 2024-12-25 13:31:19 +00:00
mondash/vendor/github.com/aws/aws-sdk-go/internal/protocol/restxml/restxml.go

58 lines
1.7 KiB
Go
Raw Normal View History

2016-01-23 12:07:07 +00:00
// Package restxml provides RESTful XML serialisation of AWS
// requests and responses.
package restxml
//go:generate go run ../../fixtures/protocol/generate.go ../../fixtures/protocol/input/rest-xml.json build_test.go
//go:generate go run ../../fixtures/protocol/generate.go ../../fixtures/protocol/output/rest-xml.json unmarshal_test.go
import (
"bytes"
"encoding/xml"
"github.com/aws/aws-sdk-go/aws/awserr"
2016-03-27 18:46:08 +00:00
"github.com/aws/aws-sdk-go/aws/request"
2016-01-23 12:07:07 +00:00
"github.com/aws/aws-sdk-go/internal/protocol/query"
"github.com/aws/aws-sdk-go/internal/protocol/rest"
"github.com/aws/aws-sdk-go/internal/protocol/xml/xmlutil"
)
// Build builds a request payload for the REST XML protocol.
2016-03-27 18:46:08 +00:00
func Build(r *request.Request) {
2016-01-23 12:07:07 +00:00
rest.Build(r)
if t := rest.PayloadType(r.Params); t == "structure" || t == "" {
var buf bytes.Buffer
err := xmlutil.BuildXML(r.Params, xml.NewEncoder(&buf))
if err != nil {
2016-03-27 18:46:08 +00:00
r.Error = awserr.New("SerializationError", "failed to encode rest XML request", err)
2016-01-23 12:07:07 +00:00
return
}
r.SetBufferBody(buf.Bytes())
}
}
// Unmarshal unmarshals a payload response for the REST XML protocol.
2016-03-27 18:46:08 +00:00
func Unmarshal(r *request.Request) {
2016-01-23 12:07:07 +00:00
if t := rest.PayloadType(r.Data); t == "structure" || t == "" {
defer r.HTTPResponse.Body.Close()
decoder := xml.NewDecoder(r.HTTPResponse.Body)
err := xmlutil.UnmarshalXML(r.Data, decoder, "")
if err != nil {
r.Error = awserr.New("SerializationError", "failed to decode REST XML response", err)
return
}
2016-03-27 18:46:08 +00:00
} else {
rest.Unmarshal(r)
2016-01-23 12:07:07 +00:00
}
}
// UnmarshalMeta unmarshals response headers for the REST XML protocol.
2016-03-27 18:46:08 +00:00
func UnmarshalMeta(r *request.Request) {
rest.UnmarshalMeta(r)
2016-01-23 12:07:07 +00:00
}
// UnmarshalError unmarshals a response error for the REST XML protocol.
2016-03-27 18:46:08 +00:00
func UnmarshalError(r *request.Request) {
2016-01-23 12:07:07 +00:00
query.UnmarshalError(r)
}