forked from aws/amazon-ecs-agent
-
Notifications
You must be signed in to change notification settings - Fork 2
/
operation.go
80 lines (67 loc) · 1.85 KB
/
operation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package api
import (
"bytes"
"strings"
"text/template"
"github.com/awslabs/aws-sdk-go/internal/util"
)
type Operation struct {
API *API `json: "-"`
ExportedName string
Name string
Documentation string
HTTP HTTPInfo
InputRef ShapeRef `json:"input"`
OutputRef ShapeRef `json:"output"`
}
type HTTPInfo struct {
Method string
RequestURI string
ResponseCode uint
}
func (o *Operation) HasInput() bool {
return o.InputRef.ShapeName != ""
}
func (o *Operation) HasOutput() bool {
return o.OutputRef.ShapeName != ""
}
func (o *Operation) Docstring() string {
if o.Documentation != "" {
return docstring(o.Documentation)
}
return ""
}
var tplOperation = template.Must(template.New("operation").Parse(`
// {{ .ExportedName }}Request generates a request for the {{ .ExportedName }} operation.
func (c *{{ .API.StructName }}) {{ .ExportedName }}Request(` +
`input {{ .InputRef.GoType }}) (req *aws.Request, output {{ .OutputRef.GoType }}) {
if op{{ .ExportedName }} == nil {
op{{ .ExportedName }} = &aws.Operation{
Name: "{{ .Name }}",
{{ if ne .HTTP.Method "" }}HTTPMethod: "{{ .HTTP.Method }}",
{{ end }}{{ if ne .HTTP.RequestURI "" }}HTTPPath: "{{ .HTTP.RequestURI }}",
{{ end }}
}
}
req = aws.NewRequest(c.Service, op{{ .ExportedName }}, input, output)
output = &{{ .OutputRef.GoTypeElem }}{}
req.Data = output
return
}
{{ .Docstring }}func (c *{{ .API.StructName }}) {{ .ExportedName }}(` +
`input {{ .InputRef.GoType }}) (output {{ .OutputRef.GoType }}, err error) {
req, out := c.{{ .ExportedName }}Request(input)
output = out
err = req.Send()
return
}
var op{{ .ExportedName }} *aws.Operation
`))
func (o *Operation) GoCode() string {
var buf bytes.Buffer
err := tplOperation.Execute(&buf, o)
if err != nil {
panic(err)
}
return strings.TrimSpace(util.GoFmt(buf.String()))
}