我正在寻找使用Go模板循环数组,我想在循环中的最后一项添加一个额外的字符串.
在python中,我可以做到
{% for host in hosts %}
{{ host }}{% if loop.last %} ;{% endif %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
为了与Go实现相同的目标,下面是Go等效的片段.
{{ range $host := $hosts }}
{{$host}}
{{ end }}
Run Code Online (Sandbox Code Playgroud)
谢谢.