【发布时间】:2021-11-25 08:41:25
【问题描述】:
我没有围棋经验。我使用了一个用 Go 编写的工具 Podman,它将其 --format 选项记录为,
-f, --format string Format the output to a Go template or json (default "json")
我可以看到我想要什么,
podman inspect localhost/myimage --format "{{.RootFS.Layers.length}}"
但是,如果我想知道有多少元素,我该怎么办?我用.count 和.length 和.len 尝试了不同的字段,但我总是得到,
can't evaluate field FieldName in type []digest.Digest
我也尝试将其调用为{{len(RootFS.Layers)}}。我只是有点粗暴地强迫它。当我执行上述操作时,我得到,
ERRO[0000] 打印检查输出时出错:模板:所有检查:1:操作数中出现意外的“(”
获取数组元素计数的正确 Go 模板是什么?
【问题讨论】:
标签: arrays go go-templates