【发布时间】:2023-02-07 13:00:27
【问题描述】:
我正在寻找以下格式的 yaml 文件。使用Go template
Custom_listeners:
Config1 : config_value
Config2 : config_value
copy_files:
- source_path: /path/to/file.txt
destination_path: /tmp/file.txt
我正在使用以下模板代码来获取值
Template :
custom_listeners: {{ range $cl := $.Vars.CustomListeners }}
{{ range $k,$v := $cl.Values }}{{ $k }}: "{{ $v }}"
{{ end }}{{ end }}
Custom listener map :
type CustomListener map[string]interface{}
我可以对上述模板进行哪些更改以创建以下格式的 yaml。在 source_path 上使用 -:
Custom_listeners:
copy_files:
- source_path1: /path/to/file.txt
destination_path: /tmp/file.txt
- source_path2: /path/to/file.txt
destination_path: /tmp/file.txt
【问题讨论】:
-
请对此进行任何更新
-
为什么不使用 yaml 包? go.dev/play/p/_GOS8Mxzs2j
标签: go go-templates