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