| 1 |
{{/* gotype: github.com/wenerme/astgo/pkg/tools/xmlgen.ManagerAction*/}} |
| 2 |
{{- define "ami/action"}} |
| 3 |
{{with .Synopsis}} {{template "comment" (printf "%v %v" $.StructName .)}} {{end}} |
| 4 |
type {{.StructName}} struct { |
| 5 |
{{- template "ami/fields" .}} |
| 6 |
} |
| 7 |
func({{.StructName}})ActionTypeName() string{ |
| 8 |
return "{{.Name}}" |
| 9 |
} |
| 10 |
func(a {{.StructName}})GetActionID() string{ |
| 11 |
return a.ActionID |
| 12 |
} |
| 13 |
func(a*{{.StructName}})SetActionID(actionID string) { |
| 14 |
a.ActionID = actionID |
| 15 |
} |
| 16 |
{{- if eq (len .Responses) 1}} |
| 17 |
func(cli*Client){{.Name}}(req {{.StructName}},opts ...RequestOption)(res *{{(index .Responses 0).StructName}}, err error) { |
| 18 |
req := &{{.StructName}}{ |
| 19 |
{{- range $_,$v:=.Syntax.Params}} |
| 20 |
{{- if $v.Required}} |
| 21 |
{{$v.Name}}: {{$v.Name | untitle}}, |
| 22 |
{{- end}} |
| 23 |
{{- end}} |
| 24 |
} |
| 25 |
res = &{{(index .Responses 0).StructName}}{} |
| 26 |
return res, cli.Action(req,res) |
| 27 |
} |
| 28 |
{{- end}} |
| 29 |
{{- if eq (len .Responses) 0}} |
| 30 |
func(cli*Client){{.Name}}({{- range $_,$v:=.Syntax.Params -}} |
| 31 |
{{- if $v.Required}} {{$v.Name | ParamName}} {{$v.Type}}, {{- end -}} |
| 32 |
{{- end -}} opts ...RequestOption)(res *Response, err error) { |
| 33 |
req := &{{.StructName}}{ |
| 34 |
{{- range $_,$v:=.Syntax.Params}} |
| 35 |
{{- if $v.Required}} |
| 36 |
{{$v.Name}}: {{$v.Name | ParamName}}, |
| 37 |
{{- end}} |
| 38 |
{{- end}} |
| 39 |
} |
| 40 |
res = &Response{} |
| 41 |
return res, cli.Action(req,res,opts...) |
| 42 |
} |
| 43 |
{{- end}} |
| 44 |
{{- end}} |
| 45 |
|
| 46 |
{{- define "comment"}} |
| 47 |
{{regexReplaceAllLiteral "(?m)^" (. | trim) "// "}} |
| 48 |
{{- end}} |
| 49 |
|
| 50 |
{{- define "ami/fields" -}} |
| 51 |
{{- range $_,$v:=.Syntax.Params -}} |
| 52 |
{{- with $v.Description}} {{template "comment" (printf "%v %v" $v.Name .)}} {{end}} |
| 53 |
{{$v.Name}} {{$v.Type}} {{with $v.Default}} // default to {{$v.Default}} {{end}} |
| 54 |
{{- end}} |
| 55 |
{{with .Syntax.Missing}} // has missing params {{- end}} |
| 56 |
{{- end}} |