restjson.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Package restjson provides RESTful JSON serialization of AWS
  2. // requests and responses.
  3. package restjson
  4. //go:generate go run -tags codegen ../../../private/model/cli/gen-protocol-tests ../../../models/protocol_tests/input/rest-json.json build_test.go
  5. //go:generate go run -tags codegen ../../../private/model/cli/gen-protocol-tests ../../../models/protocol_tests/output/rest-json.json unmarshal_test.go
  6. import (
  7. "github.com/aws/aws-sdk-go/aws/request"
  8. "github.com/aws/aws-sdk-go/private/protocol/jsonrpc"
  9. "github.com/aws/aws-sdk-go/private/protocol/rest"
  10. )
  11. // BuildHandler is a named request handler for building restjson protocol
  12. // requests
  13. var BuildHandler = request.NamedHandler{
  14. Name: "awssdk.restjson.Build",
  15. Fn: Build,
  16. }
  17. // UnmarshalHandler is a named request handler for unmarshaling restjson
  18. // protocol requests
  19. var UnmarshalHandler = request.NamedHandler{
  20. Name: "awssdk.restjson.Unmarshal",
  21. Fn: Unmarshal,
  22. }
  23. // UnmarshalMetaHandler is a named request handler for unmarshaling restjson
  24. // protocol request metadata
  25. var UnmarshalMetaHandler = request.NamedHandler{
  26. Name: "awssdk.restjson.UnmarshalMeta",
  27. Fn: UnmarshalMeta,
  28. }
  29. // Build builds a request for the REST JSON protocol.
  30. func Build(r *request.Request) {
  31. rest.Build(r)
  32. if t := rest.PayloadType(r.Params); t == "structure" || t == "" {
  33. if v := r.HTTPRequest.Header.Get("Content-Type"); len(v) == 0 {
  34. r.HTTPRequest.Header.Set("Content-Type", "application/json")
  35. }
  36. jsonrpc.Build(r)
  37. }
  38. }
  39. // Unmarshal unmarshals a response body for the REST JSON protocol.
  40. func Unmarshal(r *request.Request) {
  41. if t := rest.PayloadType(r.Data); t == "structure" || t == "" {
  42. jsonrpc.Unmarshal(r)
  43. } else {
  44. rest.Unmarshal(r)
  45. }
  46. }
  47. // UnmarshalMeta unmarshals response headers for the REST JSON protocol.
  48. func UnmarshalMeta(r *request.Request) {
  49. rest.UnmarshalMeta(r)
  50. }