我有兴趣根据某些条件向GO模板添加内容。我有一个像这样定义的结构 -
{
"resourceActions": {
"update": {
"input": null,
"output": "instance",
},
"stop": {
"input": "instanceStop",
"output": "instance",
},
"console": {
"input": "instanceConsoleInput",
"output": "instanceConsole",
},
"restart": {
"input": null,
"output": "instance",
},
"remove": {
"input": null,
"output": "instance",
},
}
我需要迭代“resourceActions”,如果在更新,重启等内部定义的操作输入为null,则生成“A()”否则生成A(输入* {inputVAL})
示例 -
{
for Update - A()
for stop - A(input *instanceStop)
for console - A(input *instanceConsoleInput)
for restart - A()
}
如何在GO-tempaltes
中执行此操作答案 0 :(得分:2)
我解决了这个问题 -
{
{{ $temp := .schema.Id }}
{{if .Input}} func (c *Container) {{$key }}(input *{{.Input}}) *{{$temp}}{} {{else}} func (c *Container) {{$key}}() *{{$temp}}{}{{end}}
}
这在GO模板中工作正常。