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