1
0
Fork 0
mirror of https://github.com/Luzifer/mondash.git synced 2024-12-23 20:41:17 +00:00
mondash/vendor/github.com/aws/aws-sdk-go/private/protocol/restxml/restxml.go

80 lines
2.7 KiB
Go
Raw Normal View History

// Package restxml provides RESTful XML serialization of AWS
2016-01-23 12:07:07 +00:00
// requests and responses.
package restxml
//go:generate go run -tags codegen ../../../models/protocol_tests/generate.go ../../../models/protocol_tests/input/rest-xml.json build_test.go
//go:generate go run -tags codegen ../../../models/protocol_tests/generate.go ../../../models/protocol_tests/output/rest-xml.json unmarshal_test.go
2016-01-23 12:07:07 +00:00
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"
"github.com/aws/aws-sdk-go/private/protocol/query"
"github.com/aws/aws-sdk-go/private/protocol/rest"
"github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil"
2016-01-23 12:07:07 +00:00
)
// BuildHandler is a named request handler for building restxml protocol requests
var BuildHandler = request.NamedHandler{Name: "awssdk.restxml.Build", Fn: Build}
// UnmarshalHandler is a named request handler for unmarshaling restxml protocol requests
var UnmarshalHandler = request.NamedHandler{Name: "awssdk.restxml.Unmarshal", Fn: Unmarshal}
// UnmarshalMetaHandler is a named request handler for unmarshaling restxml protocol request metadata
var UnmarshalMetaHandler = request.NamedHandler{Name: "awssdk.restxml.UnmarshalMeta", Fn: UnmarshalMeta}
// UnmarshalErrorHandler is a named request handler for unmarshaling restxml protocol request errors
var UnmarshalErrorHandler = request.NamedHandler{Name: "awssdk.restxml.UnmarshalError", Fn: UnmarshalError}
2016-01-23 12:07:07 +00:00
// 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 {
r.Error = awserr.NewRequestFailure(
awserr.New(request.ErrCodeSerialization,
"failed to encode rest XML request", err),
r.HTTPResponse.StatusCode,
r.RequestID,
)
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.NewRequestFailure(
awserr.New(request.ErrCodeSerialization,
"failed to decode REST XML response", err),
r.HTTPResponse.StatusCode,
r.RequestID,
)
2016-01-23 12:07:07 +00:00
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)
}