golang text/template 访问数组或 slice 切片指定索引的元素

json 数据为 { "Client": { "Platform": { "Name": "Docker Engine - Community" }, "Version": "18.09.0", "ApiVersion": "1.39", "DefaultAPIVersion": "1.39", "GitCommit": "4d60db4", "Go...

json 数据为

{
"Client": {
"Platform": {
"Name": "Docker Engine - Community"
},
"Version": "18.09.0",
"ApiVersion": "1.39",
"DefaultAPIVersion": "1.39",
"GitCommit": "4d60db4",
"GoVersion": "go1.10.4",
"Os": "windows",
"Arch": "amd64",
"BuildTime": "Wed Nov 7 00:47:51 2018",
"Experimental": false
},
"Server": {
"Platform": {
"Name": "Docker Engine - Community"
},
"Components": [
{
"Name": "Engine",
"Version": "18.09.0",
"Details": {
"ApiVersion": "1.39",
"Arch": "amd64",
"BuildTime": "Wed Nov 7 00:55:00 2018",
"Experimental": "false",
"GitCommit": "4d60db4",
"GoVersion": "go1.10.4",
"KernelVersion": "4.9.125-linuxkit",
"MinAPIVersion": "1.12",
"Os": "linux"
}
}
],
"Version": "18.09.0",
"ApiVersion": "1.39",
"MinAPIVersion": "1.12",
"GitCommit": "4d60db4",
"GoVersion": "go1.10.4",
"Os": "linux",
"Arch": "amd64",
"KernelVersion": "4.9.125-linuxkit",
"BuildTime": "2018-11-07T00:55:00.000000000+00:00"
}
}

使用 {{ (index .Server.Components 0).Name }} 访问即可

  • 发表于 2020-02-05 13:01
  • 阅读 ( 230 )
  • 分类:猿创

相关问题

0 条评论

请先 登录 后评论
不写代码的码农
Kemin

架构工程师

44 篇文章

作家榜 »

  1. Kemin 44 文章
  2. golanglover 5 文章
  3. D.Chen 4 文章
  4. salamander 1 文章
  5. 深圳-伟 1 文章
  6. 广训 1 文章
  7. PHP小菜 1 文章
  8. Undefined 0 文章