s3manger_input.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // +build codegen
  2. package api
  3. import (
  4. "bytes"
  5. "fmt"
  6. "text/template"
  7. )
  8. // S3ManagerUploadInputGoCode returns the Go code for the S3 Upload Manager's
  9. // input structure.
  10. func S3ManagerUploadInputGoCode(a *API) string {
  11. if v := a.PackageName(); v != "s3" {
  12. panic(fmt.Sprintf("unexpected API model %s", v))
  13. }
  14. s, ok := a.Shapes["PutObjectInput"]
  15. if !ok {
  16. panic(fmt.Sprintf("unable to find PutObjectInput shape in S3 model"))
  17. }
  18. a.resetImports()
  19. a.imports["io"] = true
  20. a.imports["time"] = true
  21. var w bytes.Buffer
  22. if err := s3managerUploadInputTmpl.Execute(&w, s); err != nil {
  23. panic(fmt.Sprintf("failed to execute %s template, %v",
  24. s3managerUploadInputTmpl.Name(), err))
  25. }
  26. return a.importsGoCode() + w.String()
  27. }
  28. var s3managerUploadInputTmpl = template.Must(
  29. template.New("s3managerUploadInputTmpl").
  30. Funcs(template.FuncMap{
  31. "GetDeprecatedMsg": getDeprecatedMessage,
  32. }).
  33. Parse(s3managerUploadInputTmplDef),
  34. )
  35. const s3managerUploadInputTmplDef = `
  36. // UploadInput provides the input parameters for uploading a stream or buffer
  37. // to an object in an Amazon S3 bucket. This type is similar to the s3
  38. // package's PutObjectInput with the exception that the Body member is an
  39. // io.Reader instead of an io.ReadSeeker.
  40. type UploadInput struct {
  41. _ struct{} {{ .GoTags true false }}
  42. {{ range $name, $ref := $.MemberRefs -}}
  43. {{ if eq $name "Body" }}
  44. // The readable body payload to send to S3.
  45. Body io.Reader
  46. {{ else if eq $name "ContentLength" }}
  47. {{/* S3 Upload Manager does not use modeled content length */}}
  48. {{ else }}
  49. {{ $isBlob := $.WillRefBeBase64Encoded $name -}}
  50. {{ $isRequired := $.IsRequired $name -}}
  51. {{ $doc := $ref.Docstring -}}
  52. {{ if $doc -}}
  53. {{ $doc }}
  54. {{ if $ref.Deprecated -}}
  55. //
  56. // Deprecated: {{ GetDeprecatedMsg $ref.DeprecatedMsg $name }}
  57. {{ end -}}
  58. {{ end -}}
  59. {{ if $isBlob -}}
  60. {{ if $doc -}}
  61. //
  62. {{ end -}}
  63. // {{ $name }} is automatically base64 encoded/decoded by the SDK.
  64. {{ end -}}
  65. {{ if $isRequired -}}
  66. {{ if or $doc $isBlob -}}
  67. //
  68. {{ end -}}
  69. // {{ $name }} is a required field
  70. {{ end -}}
  71. {{ $name }} {{ $.GoStructType $name $ref }} {{ $ref.GoTags false $isRequired }}
  72. {{ end }}
  73. {{ end }}
  74. }
  75. `